Sub compare_cols()
Application.ScreenUpdating = False
Set Report = Excel.Worksheets("Sheet1") 'You could also use Excel.ActiveSheet _
if you always want this to run on the current sheet.
lastRow = Report.UsedRange.Rows.Count
For i = 2 To lastRow
If Report.Cells(i, 4).Value <> "" Then 'This will omit blank cells at the end (in the event that the column lengths are not equal.
If Report.Cells(i, 4).Value <> Report.Cells(i, 6).Value Then
Report.Cells(i, 6).Interior.Color = RGB(156, 0, 6) 'Dark red background
Report.Cells(i, 6).Font.Color = RGB(255, 199, 206) 'Light red font color
End If
End If
Next i
End Sub
Sub HighlightNonMatchingDFcells()
Dim UnusedColumn As Long
UnusedColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlFormulas).Column + 1
With Intersect(Columns(UnusedColumn), ActiveSheet.UsedRange.EntireRow)
.FormulaR1C1 = "=IF(RC4<>RC6,""X"","""")"
.Value = .Value
With Intersect(.SpecialCells(xlConstants).EntireRow, Columns("F"))
.Interior.Color = RGB(156, 0, 6) 'Dark red background
.Font.Color = RGB(255, 199, 206) 'Light red font color
End With
.Clear
End With
End Sub
Here is another macro which you can also consider...
Code:Sub HighlightNonMatchingDFcells() Dim UnusedColumn As Long UnusedColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious, LookIn:=xlFormulas).Column + 1 With Intersect(Columns(UnusedColumn), ActiveSheet.UsedRange.EntireRow) .FormulaR1C1 = "=IF(RC4<>RC6,""X"","""")" .Value = .Value With Intersect(.SpecialCells(xlConstants).EntireRow, Columns("F")) .Interior.Color = RGB(156, 0, 6) 'Dark red background .Font.Color = RGB(255, 199, 206) 'Light red font color End With .Clear End With End Sub