突出显示重复匹配下一列

想比较当天与前一天的价值,并强调行项目中的每个项目的重复值,我的数据有几行,我有每天从文本文件导入数据的macros。 testing数据:

在这里输入图像说明

这是我想要的代码:

Sub Duplicates()

Dim refRng As Range, cell As Range Application.ScreenUpdating = False With Worksheets("Sheet1") Set refRng = .Range("B2", .Cells(.Rows.Count, "F").End(xlUp)).SpecialCells(XlCellType.xlCellTypeConstants) For Each cell In .Range("C2", .Cells(.Rows.Count, "D").End(xlUp)).SpecialCells(XlCellType.xlCellTypeConstants) If cell.value <> 0 Then If Not refRng.Find(what:=cell.value, LookIn:=xlFormulas, lookat:=xlWhole, MatchCase:=False) Is Nothing Then cell.Interior.color = RGB(255, 255, 0) End If Next cell End With Application.ScreenUpdating = True 

结束小组

我已经修改你的代码来实现结果。 以下代码将从列B开始到列D.相应地更改您的范围列。

 Dim cell As Range Application.ScreenUpdating = False With Worksheets("Sheet1") 'starts with Column C and matches C with B, D with C and so on.. For Each cell In .Range("C2", .Cells(.Rows.Count, "D").End(xlUp)).SpecialCells(XlCellType.xlCellTypeConstants) 'cell.Cells(1, 0) will refer previous cell If cell.Value = cell.Cells(1, 0) Then cell.Interior.Color = RGB(255, 255, 0) cell.Cells(1, 0).Interior.Color = RGB(255, 255, 0) End If Next cell End With 

每一对数值都是每个值的出现次数。 如果发生不止一次,请着色 。

编辑:比较两个相邻的值,如果它们匹配,则将它们着色。

您也可以使用条件格式。 select你想比较的列,然后:

条件格式>突出显示单元格规则>重复值