|
Option Explicit
Sub TEST0()
Dim ar, br, cr, i&, j&, dic As Object, vKey, wks As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = Sheets("数据源").[A1].CurrentRegion.Value
For i = 2 To UBound(ar)
dic(ar(i, 2)) = dic(ar(i, 2)) & " " & i
Next i
With Workbooks.Add
For Each vKey In dic.keys
cr = Split(dic(vKey))
ReDim br(1 To UBound(cr) + 1, 1 To UBound(ar, 2))
For j = 1 To UBound(ar, 2): br(1, j) = ar(1, j): Next
For i = 1 To UBound(cr)
For j = 1 To UBound(ar, 2)
br(i + 1, j) = ar(cr(i), j)
Next j
Next i
With .Worksheets.Add(after:=.Worksheets(.Worksheets.Count))
.Name = vKey
.[A1].Resize(UBound(br), UBound(br, 2)) = br
End With
Next
For Each wks In .Worksheets
If wks.Name Like "*Sheet*" Then wks.Delete
Next
End With
Set dic = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Beep
End Sub
|
|