I have two sheets: Sheet2 and Sheet3. The goal was to highlight the cells in column A of sheet3 that has a match in column A of sheet2. Here's sheet2: enter image description here. Here's for sheet3: enter image description here
Now I used this formula to determine if there's a match: =SUM(--(A2=Sheet2!$A$2:$A$4))>0
Now here's the vba code that I used to implement the conditional formatting:
Dim rng As Range
Set rng = ThisWorkbook.Worksheets("Sheet3").Range("A2:A6")
With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=SUM(--(A2=Sheet2!$A$2:$A$4))>0"
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
End With
So here's the problem: The code only highlights the first cell as shown in the image of sheet3, but there are other cells that met the criteria. I've tried recording the conditional format and run the code but it also does the same. The formula works fine if you do manual conditional formatting. I hope someone can elucidate this problem for me. Thanks.