|
参与一下。。。- Sub ykcbf() '//2024.1.25
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim arr, brr
- Dim tm: tm = Timer
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- On Error Resume Next
- p = ThisWorkbook.Path & ""
- p1 = p & "数据"
- For Each f In Fso.GetFolder(p1).Files
- If f.Name Like "*.xlsx" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- d.RemoveAll
- fn = Fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- Set sht = wb.Sheets(1)
- arr = sht.UsedRange
- For i = 3 To UBound(arr)
- s = arr(i, 8)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- For Each k In d.keys
- m = 0
- p2 = p & k & "数据"
- If Not Fso.FolderExists(p2) Then Fso.CreateFolder p2
- sht.Copy
- Set ws = ActiveWorkbook
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- With ws.Sheets(1)
- .Name = k
- .DrawingObjects.Delete
- .UsedRange.Offset(2 + d(k).Count).Clear
- For Each kk In d(k).keys
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(kk, j)
- Next
- Next
- .[a3].Resize(m, UBound(brr, 2)) = brr
- End With
- ws.SaveAs p2 & fn & "-" & k
- ws.Close
- Next
- wb.Close False
- End If
- End If
- Next f
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|