查找并突出显示重复

目前有一个名为“Scan for Unassociated CC”的button的Excel文档。

当我点击button时,以下模块启动:

Sub scan() Dim dataRange As Range Dim oneCell As Range With ThisWorkbook.Sheets("Resource Info").Range("C:C"): Rem adjust Set dataRange = Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp)) End With For Each oneCell In dataRange If 1 < Application.CountIf(dataRange, oneCell.Value) Then With oneCell .EntireRow.Interior.ColorIndex = 6 End With End If Next oneCell End Sub 

这会突出显示C列中具有重复值的所有行

添加到这个模块中,最好的方法是只突出显示列C和列K中具有重复值的行?

我是VBA和学习的新手。 任何帮助是极大的赞赏。 谢谢!

 Sub scan() Dim dataRange As Range Dim dataRange2 As Range Dim oneCell As Range Dim oneCell2 As Range Dim WS As Worksheet Set WS = ThisWorkbook.Sheets("Resource Info") WS.Cells.Interior.Color = -4142 With WS.Range("C:C"): Rem adjust Set dataRange = Range(.Cells(1, 1), .Cells(.Rows.count, 1).End(xlUp)) End With Set dataRange2 = dataRange.Offset(0, 8) For Each oneCell In dataRange Set oneCell2 = oneCell.Offset(0, 8) If 1 < Application.WorksheetFunction.CountIfs(dataRange, oneCell, dataRange2, oneCell2) Then With oneCell .EntireRow.Interior.ColorIndex = 6 End With End If Next oneCell End Sub