I am trying to compare two cells on two different workbooks. If equal, the script should further compare two other different cells on those (same) workbooks and highlight the ones that aren't equal.
I've tried the following:
Sub Compare()
Dim mycell As Range
Dim shtSheet1 As Worksheet
Dim shtSheet2 As Worksheet
Set shtSheet1 = Workbooks("100Series").Worksheets("Report")
Set shtSheet2 = Workbooks("UserWorkbook").Worksheets("User")
For Each mycell In shtSheet2.UsedRange
If Not mycell.Value = shtSheet1.Cells(mycell.Row, mycell.Column).Value Then
mycell.Interior.Color = vbRed
End If
Next
End Sub
However, this doesn't work. It throws the Subscript out of range error. I am not sure what is out of range. Each of the worksheets are 3500 rows long and 2 columns wide.
What's wrong with me current code?
Cell A1of Worbook 1 withCell A1of Worbook 2 and so on (Cell B310withCell B310of the other Workbook...)? - Benno GrimmSet shtSheet1 = Workbooks("100Series").Worksheets("Report")command, it is probably because the workbook is called "100Series.xlsx" (or something similar). - YowE3K