ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using If Statement (https://www.excelbanter.com/excel-programming/385139-using-if-statement.html)

Jeff

Using If Statement
 
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


Vergel Adriano

Using If Statement
 
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



"Jeff" wrote:

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



All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com