【发布时间】:2021-02-09 07:08:15
【问题描述】:
我有一列 Excel 数据,我试图突出显示重复值。当我运行 VBA 代码时,它会突出显示每个值(我知道有些值只列出一次)。我的数据从 b 列的第 4 行到第 45605 行以供参考。代码如下:
Sub sbHighlightDuplicatesInColumn()
Dim lastRow As Range
Dim matchFoundIndex As Long
Dim iCntr As Long
'makes sure to select the correct sheet to work in
Sheets("repeat offenders").Select
'defines the last row
'lastRow = Cells(45605, 2)
For iCntr = 4 To 45605
If Cells(iCntr, 2) <> "" Then
matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 2), Range("B4:B45605"), 0)
If iCntr <> matchFoundIndex Then
Cells(iCntr, 1).Interior.Color = vbYellow
End If
End If
Next iCntr
End Sub
【问题讨论】:
标签: vba duplicates