|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("客户-款式")
- r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- c = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
- arr = .Range("a2").Resize(r - 1, c)
- End With
- For i = 1 To UBound(arr)
- For j = 2 To UBound(arr, 2)
- If Len(arr(i, j)) <> 0 Then
- If Not d.Exists(arr(i, j)) Then
- m = 1
- ReDim brr(1 To m)
- Else
- brr = d(arr(i, j))
- m = UBound(brr) + 1
- ReDim Preserve brr(1 To m)
- End If
- brr(m) = arr(i, 1)
- d(arr(i, j)) = brr
- End If
- Next
- Next
- With Worksheets("结果")
- .UsedRange.Offset(1, 0).Clear
- r1 = 2
- For Each aa In d.keys
- brr = d(aa)
- .Cells(r1, 1) = aa
- .Cells(r1, 2).Resize(1, UBound(brr)) = brr
- r1 = r1 + 1
- Next
- End With
- End Sub
复制代码 |
|