I have been using the code outlined below; however, every once in a while, the debugger with throw a "type mismatch" error. This code simply compares two worksheets (A and B, they are in the same workbook) and highlights the differences on worksheet B (by highlighting cells yellow). How can I get rid of the "type mismatch" error?
Also, it is important to note that the worksheets are in the exact same format and each column's data starts in cell 12.
Any help would be much appreciated.
Option Explicit
Sub Compare_Tracker()
Dim varSheetA As Variant
Dim strRangeToCheck As String
Dim iRow As Long
Dim iCol As Long
strRangeToCheck = "A12:K150"
varSheetA = Worksheets("Main").Range(strRangeToCheck)
varSheetB = Worksheets("Discrepancy Compare").Range(strRangeToCheck) ' or whatever your other sheet is.
For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
For iCol = LBound(varSheetA, 2) To UBound(varSheetA, 2)
If varSheetA(iRow, iCol) <> varSheetB(iRow, iCol) Then
' Cells are different.
' Highlight different cells yellow.
Worksheets("Discrepancy Compare").Cells(iRow + 11, iCol).Interior.ColorIndex = 36
End If
Next iCol
Next iRow
End Sub