这是一个非常小的范围,但我仍然建议使用数组来存储您的范围值,然后使用数组进行比较。请参阅此示例。
Sub Sample()
Dim Ar1, Ar2
Dim i As Long, j As Long
Dim Found As Boolean
Ar1 = Range("A1:A4"): Ar2 = Range("B1:B3")
For i = LBound(Ar2) To UBound(Ar2)
Found = False
For j = LBound(Ar1) To UBound(Ar1)
If Ar1(j, 1) = Ar2(i, 1) Then
Found = True
Exit For
End If
Next j
If Found = False Then Debug.Print Ar2(i, 1) & " Is unique"
Next i
End Sub
编辑
另一种方式(虽然我仍然更喜欢上述方式)
Sub Sample()
Dim rngA As Range, rngB As Range
Dim aCell As Range, bCell As Range
Dim Found As Boolean
Set rngA = Range("A1:A4"): Set rngB = Range("B1:B3")
For Each aCell In rngB
Found = False
For Each bCell In rngA
If bCell.Value = aCell.Value Then
Found = True
Exit For
End If
Next
If Found = False Then Debug.Print aCell.Value & " Is unique"
Next
End Sub