|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub qq()
Dim r%, i%, rng As Range, mf, arr, brr, c0%, c%, m%, t, x%
Dim d, aa, bb, ws As Worksheet, wb As Workbook
t = Timer
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
x = Application.SheetsInNewWorkbook
For Each ws In Worksheets
With ws
Set rng = Nothing
Set rng = .Rows(1).Find("承运公司", , , 1)
If Not rng Is Nothing Then
c0 = rng.Column
brr = .UsedRange
r = UBound(brr)
c = UBound(brr, 2)
arr = .Cells(1, c0).Resize(r, 1)
For i = 2 To UBound(arr)
If arr(i, 1) <> "" Then
If Not d.exists(arr(i, 1)) Then
Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
End If
If Not d(arr(i, 1)).exists(ws.Name) Then
Set d(arr(i, 1))(ws.Name) = .Range("a1").Resize(r, c)
End If
Set d(arr(i, 1))(ws.Name) = Union(d(arr(i, 1))(ws.Name), .Cells(i, 1).Resize(1, c))
End If
Next
End If
End With
Next
For Each aa In d.keys
mf = ThisWorkbook.Path & "\" & aa
If Dir(mf, vbDirectory) = "" Then
MkDir mf
End If
Application.SheetsInNewWorkbook = d(aa).Count
Set wb = Workbooks.Add
m = 0
With wb
For Each bb In d(aa).keys
m = m + 1
With .Worksheets(m)
.Name = bb
d(aa)(bb).Copy .Range("a1")
.DrawingObjects.Delete
End With
Next
.SaveAs Filename:=mf & "\" & Replace(aa, "/", "-") & ".xlsx"
.Close False
End With
Next
MsgBox Timer - t
Application.SheetsInNewWorkbook = x
End Sub
|
|