|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
稍有点复杂。。。
- Sub ykcbf() '//2024.9.30
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("报表格式")
- With Sheets("源数据")
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells(5, "XFD").End(1).Column
- arr = .[a1].Resize(r, c)
- End With
- For i = 5 To UBound(arr)
- s = arr(i, 17)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- For j = 11 To 16 Step 2
- ss = arr(i, j)
- s1 = ss & "|" & arr(i, 2)
- d1(s1) = arr(i, j + 1)
- If Not d(s).exists(ss) Then Set d(s)(ss) = CreateObject("Scripting.Dictionary")
- d(s)(ss)(i) = ""
- Next
- Next
- t = d1.items
- For Each k In d.keys
- p1 = p & k & ""
- If Not fso.FolderExists(p1) Then fso.CreateFolder p1
- For Each kk In d(k).keys
- sh.Copy
- Set wb = ActiveWorkbook
- ReDim brr(1 To 100, 1 To 100)
- m = 0
- With wb.Sheets(1)
- .Name = kk
- For Each kkk In d(k)(kk).keys
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = arr(kkk, 2)
- brr(m, 3) = kk
- brr(m, 4) = arr(kkk, 5)
- brr(m, 5) = arr(kkk, 3)
- brr(m, 6) = arr(kkk, 9)
- s = brr(m, 3) & "|" & brr(m, 2)
- If d1.exists(s) Then
- brr(m, 7) = d1(s)
- End If
- brr(m, 8) = Round(brr(m, 7) * brr(m, 6), 2)
- brr(m, 9) = arr(kkk, 18)
- Next
- .[a4].Resize(m, 9) = brr
- End With
- wb.SaveAs p1 & k & "报价单-" & kk
- wb.Close
- Next
- Next
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|