带特殊排序的完整版。- Sub lqxs_px()
- Dim Arr, i&, j&, aa, n&, m&
- Dim d, k, t, k1, t1, km$, Brr
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Sheet3.Activate
- Arr = [a1].CurrentRegion
- [a2:c500].ClearContents
- For i = 2 To UBound(Arr)
- km = Left(Arr(i, 1), 4)
- If Mid(Arr(i, 1), 5, 1) <> "[" Then
- d(km) = Arr(i, 1) & "," & Arr(i, 2) & "," & Arr(i, 3)
- Else
- d1(km) = d1(km) & i & ","
- End If
- Next
- k = d.Keys: k1 = d1.Keys
- t = d1.Items: t1 = d.Items: n = 1
- [p1].Resize(d.Count) = Application.Transpose(k)
- [q1].Resize(d.Count) = Application.Transpose(t1)
- [p1].Resize(d.Count, 2).Sort [p1], 1
- Brr = [p1].CurrentRegion
- For i = 1 To UBound(Brr)
- n = n + 1: m = 0
- [p:q].ClearContents
- Cells(n, 1) = Brr(i, 2)
- If d1.Exists(CStr(Brr(i, 1))) Then
- tt = d1(CStr(Brr(i, 1)))
- tt = Left(tt, Len(tt) - 1)
- If InStr(tt, ",") Then
- aa = Split(tt, ",")
- For j = 0 To UBound(aa)
- m = m + 1
- Cells(m, 16) = Arr(aa(j), 1) & "," & Arr(aa(j), 2) & "," & Arr(aa(j), 3)
- Next
- [p1].Resize(m, 1).Sort [p1], 1
- [p1].Resize(m, 1).Copy Cells(n + 1, 1)
- n = n + m
- Else
- n = n + 1
- Cells(n, 1) = Arr(tt, 1) & "," & Arr(tt, 2) & "," & Arr(tt, 3)
- End If
- End If
- Next
- [p:p].ClearContents
- Application.DisplayAlerts = False
- [a2].Resize(UBound(Arr)).TextToColumns Comma:=True
- Application.DisplayAlerts = True
- End Sub
复制代码 |