'没有新附件,还是用1楼的附件测试的,未作多重复编码作测试,估计差不多
'满意来朵小花,这代码效率不会差。改成通用了,修改起来非常方便
Option Explicit
Sub test()
Dim arr, i, j, t, dic, s
Set dic = CreateObject("scripting.dictionary")
arr = Range("a3:c" & Cells(Rows.Count, "a").End(xlUp).Row)
ReDim brr(1 To UBound(arr, 1), 1 To 1)
For i = 1 To UBound(arr, 1)
If dic.exists(arr(i, 1)) Then
t = dic(arr(i, 1))
ReDim Preserve t(2, UBound(t, 2) + 1)
t(1, UBound(t, 2)) = arr(i, 2): t(2, UBound(t, 2)) = arr(i, 3)
Else
ReDim t(2, 0)
t(1, 0) = arr(i, 2): t(2, 0) = arr(i, 3)
End If
t(0, UBound(t, 2)) = i
dic(arr(i, 1)) = t
Next
For i = 1 To UBound(arr, 1)
t = dic(arr(i, 1)): s = vbNullString
For j = 0 To UBound(t, 2)
If i <> t(0, j) Then
If arr(i, 2) > t(1, j) And arr(i, 2) < t(2, j) Or _
arr(i, 3) < t(2, j) And arr(i, 3) > t(1, j) Then
If Len(s) = 0 Then s = "[" & arr(i, 2) & "," & arr(i, 3) & "]"
s = s & "-" & "[" & t(1, j) & "," & t(2, j) & "]"
End If
End If
Next
If Len(s) Then brr(i, 1) = s
Next
[d3].Resize(UBound(brr, 1)) = brr
End Sub
|