Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
843 B
1
Indexable
Never
Sub HighlightAddedData2()

' Declare variables for the sheets
Dim sheet1 As Worksheet, sheet2 As Worksheet
Set sheet1 = ThisWorkbook.Sheets("Sheet1") 'change this to the name of your first sheet
Set sheet2 = ThisWorkbook.Sheets("Sheet2") 'change this to the name of your second sheet

' Define the range of cells to compare
Dim rng1 As Range, rng2 As Range
Set rng1 = sheet1.Range("B7:A2500") 'change this to the range of cells in the first sheet that you want to compare
Set rng2 = sheet2.Range("B7:A2500") 'change this to the range of cells in the second sheet that you want to compare

' Create a new conditional formatting rule
For Each cell In rng1
    If WorksheetFunction.CountIf(rng2, cell.Value) = 0 Then
        cell.Interior.Color = RGB(255, 0, 0) 'set the highlight color to red
    End If
Next cell

End Sub