我想检查B列(PIB)中的所有ID,如果有重复的ID来检查A列(REGION),那么这些PIB是否有多个区域。我想检查PIB的重复区域是否具有唯一性或让我们说不同的区域。
我坚持使用以下代码标记B列并重复:
Option Explicit
Sub Test()
Dim rng As Range, rng2 As Range, rng3 As Range, cell As Range, i As Integer
Set rng = Range("A2:D400")
Set rng2 = Range("B2:B400")
Set rng3 = Range("A2:A400")
For Each cell In rng
If Application.WorksheetFunction.CountIf(rng2, cell) > 1 Then
cell.Interior.ColorIndex = 26
End If
Next
End Sub
从这段代码中,我尝试添加一些嵌套的IF,但后来没有任何反应:
Option Explicit
Sub Test()
Dim rng As Range, rng2 As Range, rng3 As Range, cell As Range, i As Integer
Set rng = Range("A2:D400")
Set rng2 = Range("B2:B400")
Set rng3 = Range("A2:A400")
For Each cell In rng
If Application.WorksheetFunction.CountIf(rng2, cell) > 1 Then
If Application.WorksheetFunction.CountIf(rng3, cell) > 1 Then
cell.Interior.ColorIndex = 26
End If
End If
Next
End Sub
谢谢!