I am trying to create a formula that compares two workbooks.
I get:
Run-time error 9.
Here is the code:
Sub Compare()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = Workbooks("Testing1.xlsx")
Set wb2 = Workbooks("Testing2.xlsx")
'Setting variable to represent last row and last column
lRow = Cells(Rows.Count, 1).End(xlUp).Row
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To lRow
For j = 2 To lCol
'Created the IF then Statement to Highlight Cells that show a difference
If wb2.Sheets("Sheet1").Cells(i, j) <> wb1.Sheets("Sheet1").Cells(i, j) Then
wb2.Sheets("Sheet1").Cells(i, j).Interior.ColorIndex = 5
End If
Next j
Next i
End Sub