|
Sub 多表同步拆分()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("Scripting.Dictionary")
Set wb1 = ThisWorkbook
For Each sht In Sheets
arA = sht.[a1].CurrentRegion
For i = 1 To UBound(arA, 2)
If arA(1, i) = "承运公司" Then j = i: Exit For
Next
For i = 2 To UBound(arA)
d(arA(i, j)) = ""
Next
Next
k = d.keys: t = d.items
For i = 0 To UBound(k)
Application.SheetsInNewWorkbook = wb1.Sheets.Count
Workbooks.Add
Set wb = ActiveWorkbook
With wb
For x = 1 To wb1.Sheets.Count
arA = wb1.Sheets(x).[a1].CurrentRegion
m = 1
For j = 1 To UBound(arA, 2)
If arA(1, j) = "承运公司" Then jj = j: Exit For
Next
For j = 2 To UBound(arA)
If arA(j, jj) = k(i) Then
m = m + 1
wb1.Sheets(x).Cells(j, 1).Resize(1, UBound(arA, 2)).Copy .Sheets(x).Cells(m, 1)
wb1.Sheets(x).Cells(1, 1).Resize(1, UBound(arA, 2)).Copy .Sheets(x).[a1]
End If
Next
Sheets(x).Name = wb1.Sheets(x).Name
.Sheets(x).[a2].CurrentRegion.Borders.LineStyle = 1
For y = 1 To UBound(arA, 2)
.Sheets(x).Columns(y).ColumnWidth = wb1.Sheets(x).Columns(y).ColumnWidth
Next
Next
End With
wb.SaveAs ThisWorkbook.Path & "\" & k(i)
wb.Close
Next
MsgBox "OK"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub |
|