|
'盆友,帮你一把,江湖救急,不必言谢,拿走就行,若有鲜花,来者不拒…………
Sub test()
Dim p$, d1 As Object, d2 As Object, ar, rng1 As Range, rng2 As Range, r&, i%, nm$
Application.ScreenUpdating = False
p = ThisWorkbook.Path & "\店铺拆分文件"
If Dir(p, vbDirectory) = "" Then MkDir p
p = p & "\"
Set d1 = CreateObject("scripting.dictionary")
With Sheet1
Set rng1 = .[a1].Resize(1, 12)
ar = .Range("e1:e" & .[e65536].End(3).Row)
For r = 2 To UBound(ar)
If Len(ar(r, 1)) Then
If Not d1.exists(ar(r, 1)) Then
Set d1(ar(r, 1)) = .Cells(r, 1).Resize(1, 12)
Else
Set d1(ar(r, 1)) = Union(d1(ar(r, 1)), .Cells(r, 1).Resize(1, 12))
End If
End If
Next
End With
Set d2 = CreateObject("scripting.dictionary")
With Sheet2
Set rng2 = .[a1].Resize(1, 24)
ar = .Range("d1:d" & .[d65536].End(3).Row)
For r = 2 To UBound(ar)
If Len(ar(r, 1)) Then
If Not d2.exists(ar(r, 1)) Then
Set d2(ar(r, 1)) = .Cells(r, 1).Resize(1, 24)
Else
Set d2(ar(r, 1)) = Union(d2(ar(r, 1)), .Cells(r, 1).Resize(1, 24))
End If
End If
Next
End With
Application.DisplayAlerts = False
Application.SheetsInNewWorkbook = 2
For i = 0 To d1.Count - 1
nm = d1.keys()(i)
With Workbooks.Add
With .Sheets(1)
.Name = "服务费"
rng1.Copy .[a1]
d1.items()(i).Copy .[a2]
.[a:l].EntireColumn.AutoFit
End With
With .Sheets(2)
.Name = "税费"
rng2.Copy .[a1]
If d2.exists(nm) Then d2(nm).Copy .[a2]
.[a:x].EntireColumn.AutoFit
End With
.SaveAs p & nm & ".xlsx", xlOpenXMLWorkbook
.Close
End With
Next
Set rng1 = Nothing
Set rng2 = Nothing
Set d1 = Nothing
Set d2 = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = False
MsgBox "OK!"
End Sub'附件有2M多,无法上传
|
评分
-
2
查看全部评分
-
|