字典排序- Sub yy()
- Dim d, arr, i&, j&, k&, m&, n&, x&, y&, r&
- Set d = CreateObject("Scripting.Dictionary")
- With Sheet1
- r = .Cells(Rows.Count, 6).End(3).Row
- arr = .Range("a1:g" & r).Value
- End With
- x = UBound(arr, 2): y = UBound(arr)
- For i = 2 To y
- If arr(i, 1) = "" Then
- arr(i, x) = arr(i - 1, 1): arr(i, x) = arr(i - 1, x)
- Else
- arr(i, x) = arr(i, 1)
- End If
- d(arr(i, x)) = ""
- Next
- ReDim brr(1 To y - 1, 1 To x)
- For i = 1 To d.Count
- n = Application.Small(d.keys, i)
- For j = 2 To y
- If arr(j, x) = n Then
- m = m + 1
- For k = 1 To x - 1
- brr(m, k) = arr(j, k)
- Next
- End If
- Next
- Next
- With Sheet2
- .[a1].CurrentRegion.ClearContents
- .[a2].Resize(y - 1, x - 1) = brr
- .[a1] = Sheet1.[a1].Value
- End With
- Set d = Nothing
- End Sub
复制代码 |