|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 拆分为工作簿()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long
Dim arr()
Dim d As Object
Dim sh As Worksheet
Dim rng As Range
Set sh = ThisWorkbook.ActiveSheet
Set d = CreateObject("scripting.dictionary")
With sh
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:az" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
d(Trim(ar(i, 3))) = ""
End If
Next i
For Each k In d.keys
sh.Copy
Set wb = ActiveWorkbook
With wb.Worksheets(1)
For i = 2 To UBound(ar)
If Trim(.Cells(i, 3)) <> k Then
If rng Is Nothing Then
Set rng = .Rows(i)
Else
Set rng = Union(rng, .Rows(i))
End If
End If
Next i
For Each sp In .Shapes
sp.Delete
Next sp
End With
If Not rng Is Nothing Then rng.Delete
Set rng = Nothing
wb.SaveAs Filename:=ThisWorkbook.Path & "\" & k & ".xlsx"
wb.Close
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub |
评分
-
1
查看全部评分
-
|