Using If Statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I would like to compare to excel file 2 excel file cell/column and
check if it is different.

here is my idea:

IF xls1 A2 is found in xls2 column B(ANY CELL IN COLUMN B)
then check IF xls1 B2 is equal to xls2 B(CELL OF THE RESULT ABOVE)
IF equal then input "ok" in xls1 F2
If not equal input "wrong" in xls1 F2

else input "not found" in xls1 F2
 
Assuming the sheets that you're trying to compare in the 2 excel files are
both Sheet1:

Sub test()
Dim xls1 As Workbook
Dim xls2 As Workbook
Dim c As Range

Set xls1 = Workbooks.Open("C:\workbook1.xls")
Set xls2 = Workbooks.Open("C:\Workbook2.xls")

With xls1.Worksheets("Sheet1")
Set c = xls2.Worksheets("Sheet1").Range("B:B").Find(.Range("A2").Text)
If c Is Nothing Then
.Range("F2").Value = "not found"
ElseIf .Range(c.Address).Value = c.Value Then
.Range("F2").Value = "ok"
Else
.Range("F2").Value = "wrong"
End If
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top