|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 拆分为工作表()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long
Dim d As Object
Dim sh As Worksheet
Set sh = ThisWorkbook.ActiveSheet
Dim rn As Range
Set d = CreateObject("scripting.dictionary")
Application.DisplayAlerts = False
For Each Sht In Sheets
If Sht.Index > 1 Then
Sht.Delete
End If
Next Sht
Application.DisplayAlerts = True
With sh
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:c" & r)
Set rn = .Rows(3)
End With
For i = 4 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
Next i
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 4 To UBound(ar)
If Trim(ar(i, 1)) = k Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
End If
Next i
Set Sht = Sheets.Add(after:=Sheets(Sheets.Count))
With Sht
.Name = k
rn.Copy .[a1]
.[a2].Resize(n, UBound(br, 2)) = br
.[a2].Resize(n, UBound(br, 2)).Borders.LineStyle = 1
End With
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|