以下是引用丸究阵引在2008-5-30 13:44:53的发言:粗看起来没问题!晚上再说! 可用字典实现: Sub macro1() Dim arr, i, dic, d Set dic = CreateObject("scripting.dictionary") arr = [a1].CurrentRegion ReDim brr(2 To UBound(arr)) For i = 2 To UBound(arr) dic(arr(i, 2) & " ") = arr(i, 2) If Not dic.exists(arr(i, 2)) Then dic(arr(i, 1)) = " " & arr(i, 2) & " " & arr(i, 1) Else dic(arr(i, 1)) = dic(arr(i, 2)) & " " & arr(i, 1) End If For Each d In dic.keys If d <> arr(i, 2) And dic(d) Like " " & arr(i, 1) & " #*" Then dic(d) = Replace(dic(d), " " & arr(i, 1) & " ", dic(arr(i, 1)) & " ") Next Next Debug.Print Join(dic.items, vbCrLf) End Sub
Returns: 23 0 23 1 0 23 2 11 0 22 11 3 22 0 22 4 0 22 11 5 0 22 6 0 22 7 1 0 23 1 8 0 22 9 0 0 10 0 22 11 0 22 12 0 22 13 0 22 14 26 0 23 24 25 26 15 0 23 24 25 26 16 0 22 17 0 23 24 25 26 18 0 22 19 0 22 20 0 21 0 22 0 23 0 23 24 24 0 23 24 25 25 0 23 24 25 26 0 23 24 27 |