我有一列数据,其中有字符串值。我想通过该列中的每个单元格进行比较,并检查值是否重复。比较需要全文以及通配符。使用vba删除excel中的重复行
下面是我的数据的截图
,如果你看到的截图,该公司CES有限公司第3排的存在,以及对列17与另一家公司ECLERX SERVICES LTD沿着| CES有限公司。所以我想突出显示这样的重复值。
下面是我写的
Dim rangeToUse As Range, singleArea As Range, cell1 As Range, cell2 As Range, i As Integer, j As Integer
Set rangeToUse = Selection
Cells.Interior.ColorIndex = 0
Cells.Borders.LineStyle = xlNone
For Each singleArea In rangeToUse.Areas
singleArea.BorderAround ColorIndex:=1, Weight:=xlThin
Next singleArea
For i = 1 To rangeToUse.Areas.Count
For Each cell1 In rangeToUse.Areas(i)
MsgBox cell1.Value
For j = 1 To rangeToUse.Areas.Count
For Each cell2 In rangeToUse.Areas(j)
If cell1.Value = cell2.Value Then
cell2.Interior.ColorIndex = 38
End If
MsgBox cell2.Value
Next cell2
Next j
Next cell1
Next i
但是代码突出显示所有不同的细胞中的代码。任何人都可以让我知道我在做什么错?
当谈到创建在Excel中唯一值的列表,没有什么比一个很好的旧['Dictionary'对象(http://stackoverflow.com/questions/915317/does-vba - 具备词典结构)。 – Tim
它们将是相同的颜色,因为当你遍历列表时,在某个时候,'cell1'和'cell2'将引用同一个单元格,这当然会通过你的匹配测试。您需要排除cell1与自身进行比较。 –