|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按指定列拆分工作表并保留列宽行高()
Dim sh As Worksheet, d As Object, ar, i&, s$, k, rg As Range
If Sheets.Count > 1 Then
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Name <> "固定区域" Then sh.Delete
Next
Application.DisplayAlerts = True
End If
Set sh = ThisWorkbook.Sheets(1)
If sh.AutoFilterMode Then sh.AutoFilterMode = False
sh.UsedRange = sh.UsedRange.Value
ar = ActiveSheet.Range("a1").CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(ar)
s = ar(i, 6)
If s <> "" Then d(s) = ""
Next
If d.Count > 0 Then
Application.ScreenUpdating = False: Application.DisplayAlerts = False
For Each k In d.keys
Sheets(1).Copy after:=Sheets(Sheets.Count)
Set sh = ActiveSheet
With sh
.Name = k
.UsedRange.AutoFilter field:=6, Criteria1:="<>" & k
.UsedRange.Offset(1).SpecialCells(xlCellTypeVisible).Delete
.UsedRange.AutoFilter
End With
Next
Sheets(1).Select
Application.ScreenUpdating = True: Application.DisplayAlerts = True
MsgBox "亲,成功拆分出" + CStr(d.Count) & "个工作表", vbInformation, "提示"
End If
End Sub
|
|