|
加个行合计
- Sub ykcbf() '//2024.7.26 多簿汇总
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- f = p & "\价格表.xlsx"
- Set sh = ThisWorkbook.Sheets("每日汇总")
- Set wb = Workbooks.Open(f, 0)
- arr = wb.Sheets(1).UsedRange
- wb.Close 0
- ReDim brr(1 To UBound(arr), 1 To 100)
- m = 2: n = 1
- brr(1, 1) = "日期": brr(1, 2) = arr(1, 1)
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(2, n) = s
- End If
- d(arr(i, 2)) = arr(i, 1)
- Next
- On Error Resume Next
- For Each f In fso.GetFolder(p).Files
- fn = fso.GetBaseName(f)
- If Val(fn) Then
- m = m + 1
- rq = CDate("2024/" & Replace(Replace(fn, "号", ""), ".", "/"))
- brr(m, 1) = rq
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- With sht
- arr = .UsedRange.Value
- For i = 6 To UBound(arr)
- If Val(arr(i, 1)) Then
- If arr(i, 2) <> Empty Then
- s = arr(i, 2)
- If d.exists(s) Then arr(i, 8) = d(s)
- c = d(arr(i, 8))
- brr(m, c) = brr(m, c) + Val(arr(i, 7))
- End If
- End If
- Next
- .UsedRange.Value = arr
- End With
- Next
- wb.Close 1
- End If
- Next
- m = m + 1
- brr(m, 1) = "合计"
- For j = 2 To n
- Sum = 0
- For i = 3 To m - 1
- Sum = Sum + brr(i, j) '//求每列合计
- Next
- brr(m, j) = Sum
- Next
- n = n + 1
- brr(2, n) = "合计"
- For i = 3 To m
- Sum = 0
- For j = 2 To n - 1
- Sum = Sum + brr(i, j) '//求每行合计
- Next
- brr(i, n) = Sum
- Next
- With sh
- .UsedRange.Clear
- .Cells.Interior.ColorIndex = 0
- .[a1].Resize(2, n).Interior.Color = 49407
- .[a3].Resize(m - 2, 1).Interior.Color = 5296274
- With .[a1].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- arr = .UsedRange
- .[a1].Resize(2).Merge
- .[b1].Resize(, n - 1).Merge
- .[a3].Resize(m - 3, n).Sort .[a3], 1
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|