i have applied this vba macro on my excel sheet to compare sheet1 and sheet2 data in given range & if any different data should found in sheet1 or sheet2 in given range then highlight that row data with color
and if i remove or delete that highlighted row data in that sheet then the highlighted color should be remove
can any one correct this code
and if i remove or delete that highlighted row data in that sheet then the highlighted color should be remove
can any one correct this code
VBA Code:
Sub CompareHighlight()
Dim varSheetA As Variant
Dim varSheetB As Variant
Dim strRangeToCheck As String
Dim iRow As Long
Dim iCol As Long
Set varSheetA = Sheet1
Set varSheetB = Sheet2
strRangeToCheck = "A1:B11"
Debug.Print Now
varSheetA = Worksheets("Sheet1").Range(strRangeToCheck)
varSheetB = Worksheets("Sheet2").Range(strRangeToCheck)
Debug.Print Now
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
varSheetA(iRow, iCol).Interior.ColorIndex = 27
varSheetB(iRow, iCol).Interior.ColorIndex = 27
Else
varSheetA(iRow, iCol).Interior.ColorIndex = xlNone
varSheetB(iRow, iCol).Interior.ColorIndex = xlNone
Else
End If
End If
Next iCol
Next iRow
End Sub