|
楼主 |
发表于 2024-8-11 13:08
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub tyji()
Dim r&, Arr, Brr, Crr, Dic As Object, i&, j&, k&, sumAsNumeric As Double
ReDim Crr(0 To 999, 0 To 12)
Set Dic = CreateObject("Scripting.Dictionary")
With Worksheets("数据源")
r = .Cells(Rows.Count, 1).End(xlUp).Row - 1
Arr = .Range("A2").Resize(r, 2)
Brr = .Range("H2").Resize(r, 1)
End With
For i = 1 To r
If Dic.Exists(Arr(i, 1)) Then
j = Dic(Arr(i, 1))
k = Month(Arr(i, 2))
Crr(j, k) = Crr(j, k) + Brr(i, 1)
Else
j = Dic.Count: Dic(Arr(i, 1)) = j: Crr(j, 0) = Arr(i, 1)
k = Month(Arr(i, 2))
Crr(j, k) = Crr(j, k) + Brr(i, 1)
End If
Next i
With Worksheets("统计查看")
Dim strValue As String
Dim unit As String
unit = "元" ' 单位
For i = 0 To Dic.Count
For j = 0 To 12
If Crr(i, j) > 0 Then
strValue = Format(Crr(i, j), "0.00") & unit
Else
strValue = ""
End If
.Cells(i + 3, j + 1).Value = strValue
Next j
sumAsNumeric = WorksheetFunction.Sum(.Range(.Cells(i + 3, 2), .Cells(i + 3, 13)))
.Cells(i + 3, 14).Value = Format(sumAsNumeric, "0.00") & unit
Next i
End With
Set Dic = Nothing
End Sub
按照你这个我添加了最后一行的合计后,显示出来的结果没办法完全显示,只有0.00是什么情况 |
|