|
|
- Sub ykcbf() '2025.12.16
- ApplicationSettings False
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & Application.PathSeparator
- With Application.FileDialog(msoFileDialogFilePicker)
- .InitialFileName = ThisWorkbook.Path & ""
- .Title = "请选择对应Excel文件"
- .AllowMultiSelect = False
- .Filters.Clear
- .Filters.Add "Excel文件", "*.xls*"
- If .Show Then f = .SelectedItems(1) Else Exit Sub
- End With
- bt = Val(Application.InputBox("请输入标题行数:默认是1行", "标题行数", 1))
- col = Val(Application.InputBox("请输入拆分列列号:默认是8列", "拆分依据列列号", 8))
- If col = 0 Or bt = 0 Then Exit Sub
- tm = Timer
- Set wb = Workbooks.Open(f, 0)
- wb.Sheets(1).Copy
- Set wb1 = ActiveWorkbook
- Set sh = wb1.Sheets(1)
- wb.Close False
- With sh
- r = .Cells(.Rows.Count, col).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)
- If Len(arr(i, col) & "") > 0 Then
- s = arr(i, col)
- If Not d.Exists(s) Then d(s) = True
- End If
- Next i
- For Each k In d.Keys
- sh.Copy After:=wb1.Sheets(wb1.Sheets.Count)
- With wb1.Sheets(wb1.Sheets.Count)
- .DrawingObjects.Delete
- .Name = CStr(k)
- .Rows(bt).AutoFilter col, "<>" & k
- .Rows(bt + 1 & ":" & r).Delete
- .AutoFilterMode = False
- End With
- Next
- sh.Activate
- wb1.SaveAs p & "工作簿另存.xlsx", 51
- wb1.Close False
- ApplicationSettings True
- If d.Count > 0 Then
- MsgBox "■ 拆分操作完成 ■" & vbCrLf & _
- "═══════════════════════" & vbCrLf & _
- "■ 处理时间: " & Format(Timer - tm, "0.000") & "秒" & vbCrLf & _
- "■ 处理行数: " & UBound(arr) - bt & "行" & vbCrLf & _
- "■ 生成表数: " & d.Count & "个" & vbCrLf & _
- "═══════════════════════", vbInformation, "执行报告"
- End If
- End Sub
- Private Sub ApplicationSettings(ByVal Reset As Boolean)
- With Application
- .ScreenUpdating = Reset
- .DisplayAlerts = Reset
- .Calculation = IIf(Reset, xlCalculationAutomatic, xlCalculationManual)
- .AskToUpdateLinks = Reset
- .EnableEvents = Reset
- End With
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|