|
'如果组非常多就不用字典,否则速度会更慢。不假死可以在2个循环中个加入一个doevents,但速度会慢很多,好处就是你点一下它不假死机,最后弹出窗口就算结束了。
'组不多就不要修改代码,仅在相应的位置加入2个doevents就可以了。
Option Explicit
Sub test()
Dim i, j, arr, n, dic, first As Boolean, t As String
arr = Range("a2:c" & Cells(Rows.Count, "a").End(xlUp).Row)
For i = 2 To UBound(arr, 1): arr(i, 3) = vbNullString: Next
For i = 1 To UBound(arr, 1)
If Len(arr(i, 3)) = 0 Then
first = True: t = vbNullString
For j = 1 To UBound(arr, 1)
If Len(arr(j, 3)) = 0 Then
If first Then
n = n + 1: first = False: arr(i, 3) = n
t = "|" & arr(i, 1) & "|" & arr(i, 2) & "|"
Else
If InStr(t, arr(j, 1)) > 0 Or InStr(t, arr(j, 2)) > 0 Then
arr(j, 3) = n
t = t & "|" & arr(j, 1) & "|" & arr(j, 2) & "|"
End If
End If
End If
DoEvents '<--
Next
End If
DoEvents '<--
Next
[a2].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
MsgBox "ok!"
End Sub |
|