|
|
- Sub ykcbf() '//2025.11.24 总表拆分为多工作簿
- Dim tm As Double: tm = Timer
- Dim d As Object, p As String
- Dim ws As Workbook, sh As Worksheet
- Dim arr, bt As Long, col As Long
- Dim i As Long, s As String, k As Variant
- Dim wb As Workbook, rng As Range
- With Application
- .ScreenUpdating = False
- .DisplayAlerts = False
- .Calculation = xlCalculationManual
- .EnableEvents = False
- End With
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & Application.PathSeparator
- p1 = p & "拆分数据" & Application.PathSeparator
- Set ws = ThisWorkbook
- xm = "路线分段" '//拆分表表名
- Set sh = ws.Sheets(xm)
- arr = sh.UsedRange.Value
- bt = 1: col = 3
- For i = bt + 1 To UBound(arr)
- s = Trim(arr(i, col))
- If s = "" Then Exit For
- If Not d.Exists(s) Then d.Add s, arr(i, 2)
- Next i
- For Each k In d.Keys
- ws.Sheets.Copy
- Set wb = ActiveWorkbook
- With wb.Sheets(xm)
- .Activate
- .Name = d(k)
- .DrawingObjects.Delete
- .Rows(bt).AutoFilter col, "<>" & k
- .UsedRange.Offset(bt).EntireRow.Delete
- .AutoFilterMode = False
- End With
- wb.SaveAs p1 & d(k) & ".xlsm", 52
- wb.Close False
- Next k
- With Application
- .DisplayAlerts = True
- .ScreenUpdating = True
- .Calculation = xlCalculationAutomatic
- .EnableEvents = True
- End With
- MsgBox "拆分完成!共用时:" & Format(Timer - tm, "0.000") & " 秒" & vbCrLf & _
- "共生成 " & d.Count & " 个工作簿。", vbInformation
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|