我正在尝试浏览列并突出显示列中的重复项。我使用记录宏来了解我需要什么,但我不确定如何在许多列中应用它。突出显示所有列将不起作用,因为许多名称重复。我需要找出一个名称是否在列表中重复多次。
这是我到目前为止的代码:
Sub findDuplicates()
Application.Goto Reference:="R3C18:R89C18"
Application.Goto Reference:="R3C18:R88C18"
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16751204
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10284031
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("R21").Select
End Sub
这是我拥有的代码,它遍历 B3:OA3 范围内的每一列,并按颜色和字母排序。我的想法是,因为此代码逐列并排序,我可以简单地添加到它以突出显示它已经排序的列中的重复项。但我不确定我会怎么做。
Sub sortColorThenAlpha()
'sort by color then by alphabet
Dim rngFirstRow As Range
Dim rng As Range, rngSort As Range
Dim ws As Worksheet
Application.ScreenUpdating = False
Set ws = ActiveSheet
Set rngFirstRow = ws.Range("B3:OA3")
For Each rng In rngFirstRow.Cells
With ws.Sort
Set rngSort = rng.Resize(86, 1) 'to row 88
.SortFields.Clear
.SortFields.Add(rng, xlSortOnCellColor, xlAscending, , xlSortNormal). _
SortOnValue.Color = RGB(198, 239, 206)
.SortFields.Add Key:=rng, SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.SetRange rngSort
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next rng
Application.ScreenUpdating = True
End Sub
这就是我正在看的。黄色的条件格式是我试图应用于第 3 行和第 88 行之间的每一列的格式。