|
|
- Sub ykcbf() '//2025.12.17 原格式拆分成多工作簿
- ApplicationSettings False
- Set d = CreateObject("scripting.dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- bt = 3 '//标题行号
- col = 3 '//拆分列号
- Dim tm: tm = Timer
- Set sh = ThisWorkbook.Sheets("汇总")
- fgf = Application.PathSeparator
- p = ThisWorkbook.Path & fgf
- p1 = p & "生成的新工作簿目录" & fgf
- If Not fso.FolderExists(p1) Then fso.CreateFolder p1
- With sh
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(bt, Columns.Count).End(xlToLeft).Column
- arr = .[a1].Resize(r, c).Value
- End With
- For i = bt + 1 To UBound(arr, 1)
- s = arr(i, col)
- If Len(s & "") > 0 Then
- If Not d.Exists(s) Then d(s) = s
- End If
- Next i
- For Each k In d.Keys
- sh.Copy: Set wb = ActiveWorkbook
- With wb.Sheets(1)
- .DrawingObjects.Delete
- .Name = CStr(k)
- .Rows(bt).AutoFilter col, "<>" & k
- .Rows(bt + 1 & ":" & r).Delete
- .AutoFilterMode = False
- End With
- wb.SaveAs p1 & k & ".xlsx", 51
- wb.Close False
- Next
- ApplicationSettings True
- MsgBox "共用时:" & Format(Timer - tm, "0.000") & " 秒!" & vbCrLf & _
- "成功拆分成:" & d.Count & " 个工作簿。"
- ApplicationSettings True
- End Sub
- Private Sub ApplicationSettings(ByVal Reset As Boolean)
- With Application
- .ScreenUpdating = Reset: .DisplayAlerts = Reset
- .Calculation = IIf(Reset, xlCalculationAutomatic, xlCalculationManual)
- .AskToUpdateLinks = Reset: .EnableEvents = Reset: .EnableAnimations = Reset
- End With
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|