我想创建一个在A列中找到重复值的宏,然后突出显示K列和L列中的相应单元格。
例如,它应该是这样的:
这是我到目前为止的代码,让我知道我做错了什么...我只是突出显示所有行K和L,因此没有完成我想要它做的事情。
Public Sub HighlightDuplicates()
Dim Color As Integer
Dim rng As Range
Dim rngCell As Variant
Dim LR As Long
Dim Val
LR = Cells(ROWS.Count, "A").End(xlUp).row
Set rng = Range("K1:L12740" & LR)
Color = xlThemeColorAccent1
For Each rngCell In rng.Cells
Val = rngCell.Text
If (WorksheetFunction.CountIf(Range("A2:A" & rngCell.row), Val) = 1) Then
rngCell.Interior.Pattern = xlNone
Else
rngCell.Interior.ColorIndex = Color
End If
Next
End Sub