|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
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, 4)) <> "" Then
d(Trim(ar(i, 4))) = ""
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, 4)) <> 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
查看全部评分
-
|