|
Sub 拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Application.DisplayAlerts = False
For Each sht In Worksheets
If sht.Index > 1 Then
sht.Delete
End If
Next sht
Application.DisplayAlerts = True
With Sheets("Sheet2")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:h" & r)
Set rn = .Rows(1)
For i = 2 To UBound(ar)
If Not IsError(ar(i, 1)) Then
If Trim(ar(i, 1)) <> "" Then
If Not d.exists(Trim(ar(i, 1))) Then
Set d(Trim(ar(i, 1))) = .Cells(i, 1).Resize(1, 8)
Else
Set d(Trim(ar(i, 1))) = Union(d(Trim(ar(i, 1))), .Cells(i, 1).Resize(1, 8))
End If
End If
End If
Next i
End With
x = d.keys
For i = 0 To UBound(x)
Set sh = Sheets.Add(after:=Sheets(Sheets.Count))
With ActiveSheet
.Name = x(i)
rn.Copy .[a1]
d.items()(i).Copy .[a2]
For j = 8 To 2 Step -1
If j = 2 Or j = 4 Or j = 6 Then
.Columns(j).Delete
End If
Next j
End With
Next i
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|