Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,786
- Office Version
- 365
- Platform
- Windows
I have the code below that has worked fine for some time but now it is causing me problems on a certain WB. It highlights in red what is on sheet 2 but not on sheet 1. I am using it now but it is highlighting certain numbers that are on both sheets. These come in the form of years or 4 digit numbers i.e 1997, 2008 etc..
It only does it with some and not all. Can someone help please.
It only does it with some and not all. Can someone help please.
Code:
Sub OnSheet2NotSheet1()
Dim LR1&, lc1&, LR2&, lc2&
Dim d As Object, a1, a2, e, i&, j&
With Sheets("sheet1")
LR1 = .Cells.Find("*", After:=.Cells(1), SearchOrder:=xlByRows, _
searchdirection:=xlPrevious).Row
lc1 = .Cells.Find("*", After:=.Cells(1), SearchOrder:=xlByColumns, _
searchdirection:=xlPrevious).Column
a1 = .Cells(1).Resize(LR1, lc1)
End With
With Sheets("sheet2")
LR2 = .Cells.Find("*", After:=.Cells(1), SearchOrder:=xlByRows, _
searchdirection:=xlPrevious).Row
lc2 = .Cells.Find("*", After:=.Cells(1), SearchOrder:=xlByColumns, _
searchdirection:=xlPrevious).Column
a2 = .Cells(1).Resize(LR2, lc2)
End With
Set d = CreateObject("scripting.dictionary")
d.comparemode = 1
For Each e In a1: d(e) = 1: Next e
For i = 1 To LR2: For j = 1 To lc2
If d(a2(i, j)) <> 1 Then _
Sheets("sheet2").Cells(i, j).Interior.ColorIndex = 3
Next j, i
End Sub