|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 ykcbf1100 于 2024-5-13 12:38 编辑
按用料单位和供应商拆分。
- Sub ykcbf() '//2024.5.13
- Dim arr, d, zj(), sum()
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("供应明细表")
- bt = 3: col = 6
- For Each sht In ws.Sheets
- If sht.Name <> sh.Name And sht.Name <> "说明" And sht.Name <> "数据" Then sht.Delete
- Next
- arr = ws.Sheets("数据").UsedRange
- For i = bt + 1 To UBound(arr)
- s = arr(i, col): ss = arr(i, 2)
- If s <> Empty Then
- If Not d.Exists(s) Then Set d(s) = CreateObject("scripting.dictionary")
- If Not d(s).Exists(ss) Then Set d(s)(ss) = CreateObject("scripting.dictionary")
- d(s)(ss)(i) = i
- End If
- Next i
- b = [{2,7,4,5}]: bb = [{4,5,6,9,10}]
- For Each k In d.keys
- ReDim zj(1 To 5)
- sh.Copy after:=ws.Sheets(ws.Sheets.Count)
- Set sht = ws.Sheets(ws.Sheets.Count)
- ReDim brr(1 To 30, 1 To 10)
- m = 0: lc = 26
- With sht
- n = 0
- .Name = k
- .[a2] = "供应明细表--" & .Name
- For Each kk In d(k).keys
- ReDim sum(1 To 5)
- For Each kkk In d(k)(kk).keys
- m = m + 1: n = n + 1
- brr(m, 1) = n
- For j = 1 To UBound(b)
- brr(m, j + 1) = arr(kkk, b(j))
- Next
- brr(m, 6) = Application.WorksheetFunction.Round(brr(m, 5) * 0.05, 2)
- brr(m, 7) = "当前日期加一年"
- brr(m, 8) = "5%"
- brr(m, 9) = Application.WorksheetFunction.Round(brr(m, 4) * Val(brr(m, 8)), 2)
- brr(m, 10) = Application.WorksheetFunction.Round(brr(m, 9) * 1.06, 2)
- For x = 1 To 5
- sum(x) = sum(x) + brr(m, bb(x))
- Next
- Next
- m = m + 1
- brr(m, 2) = kk & " 小计"
- For x = 1 To 5
- brr(m, bb(x)) = sum(x)
-
- zj(x) = zj(x) + sum(x)
- Next
- Next
- m = m + 1
- brr(m, 2) = "总计"
- For x = 1 To 5
- brr(m, bb(x)) = zj(x)
- Next
- k = lc - m
- If k > 0 Then .Rows(6 & ":" & 5 + k).Delete
- If k < 0 Then
- For i = 1 To m - lc
- .Cells(10 + i, 1).EntireRow.Insert
- Next i
- End If
- .[a5].Resize(m, 10) = brr
- For i = 5 To 5 + m - 1
- .Cells(i, 1).Resize(1, 10).ShrinkToFit = True
- If Val(.Cells(i, 1)) = 0 Then
- .Cells(i, 1).Resize(1, 10).Font.Bold = True
- .Cells(i, 1).Resize(1, 10).Font.Name = "黑体"
- End If
- Next
- End With
- Next k
- ws.Sheets("数据").Activate
- Set d = Nothing
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|