|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 多条件汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("23-24 系统数据")
r = .Cells(Rows.Count, 12).End(xlUp).Row
ar = .Range("a1:l" & r)
End With
With Sheets("2021-2024系统数据看板")
.UsedRange.Offset(7) = Empty
ksy = .[c2]
jsy = .[e2]
zb = .[c3]
If ksy = "" Or jsy = "" Then MsgBox "请输入年份范围!": End
br = .Range("b7:m" & r + 10)
For j = 2 To UBound(br, 2)
d(br(1, j)) = j
Next j
k = 1
For i = 2 To UBound(ar, 1)
If ar(i, 1) <> "" Then
If IsDate(ar(i, 1)) Then
nf = Year(ar(i, 1))
If nf >= ksy And nf <= jsy Then
If Trim(ar(i, 12)) = zb Then
yf = Month(ar(i, 1))
zd = nf & yf
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = nf
br(k, 2) = yf
End If
br(t, 3) = br(t, 3) + ar(i, 8)
lh = d(ar(i, 9))
br(t, lh) = br(t, lh) + ar(i, 8)
End If
End If
End If
End If
Next i
If k = 1 Then MsgBox "没有符合条件的数据!": End
.[b7].Resize(k, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|