数据量大,在单元格中循环,当然会很慢,且循环的次数是乘积的,用数组就不一样了
此代码运用了字典方法来判断,同时是用数组来循环的,循环次数为2次,你试下
代码如下
Sub test()
Dim arr, x&
Dim d As Object
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.UsedRange
For x = 1 To UBound(arr)
d(arr(x, 2)) = ""
Next x
For x = 1 To UBound(arr)
If d.exists(arr(x, 1)) Then
Sheet1.Cells(x, 1).Interior.ColorIndex = 6
End If
Next x
d.RemoveAll
Erase arr
End Sub