|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a1:a" & r)
- For i = 2 To UBound(arr)
- If Len(arr(i, 1)) <> 0 Then
- bm = CStr(arr(i, 1))
- End If
- If Not d.exists(bm) Then
- Set d(bm) = .Range("b1:c1")
- End If
- Set d(bm) = Union(d(bm), .Cells(i, 2).Resize(1, 2))
- 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
复制代码 |
|