|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("数据")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For j = 4 To UBound(arr, 2)
- For i = 1 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- If Not d.exists(arr(1, j)) Then
- Set d(arr(1, j)) = .Range("a1:b1")
- End If
- Set d(arr(1, j)) = Union(d(arr(1, j)), .Cells(i, 1).Resize(1, 2))
- End If
- Next
- Next
- End With
- For Each aa In d.keys
- On Error Resume Next
- Set ws = Worksheets(aa)
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = aa
- End If
- On Error GoTo 0
- With Worksheets(aa)
- .Cells.Clear
- d(aa).Copy .Range("a1")
- End With
- Next
- End Sub
复制代码 |
|