- Private Sub CommandButton2_Click()
- j = Sheet1.[a65536].End(3).Row
- ReDim ar(1 To j, 1 To 6)
- For i = 2 To j
- If Sheet1.Cells(i, 1) & "" = ComboBox2 And Sheet1.Cells(i, 3) & "" = ComboBox1 Then
- l = l + 1
- ar(l, 1) = ComboBox2
- ar(l, 3) = Sheet1.Cells(i, 2)
- ar(l, 4) = Sheet1.Cells(i, 5)
- ar(l, 5) = Sheet1.Cells(i, 6)
- ar(l, 6) = Sheet1.Cells(i, 7)
- End If
- Next
- ar(l + 1, 4) = "本期合计"
- ar(l + 2, 4) = "本年合计"
- ar(l + 1, 5) = Application.SumIfs(Sheet1.[f:f], Sheet1.[a:a], ComboBox2 & "", Sheet1.[c:c], ComboBox1 & "")
- ar(l + 2, 5) = Application.SumIf(Sheet1.[c:c], ComboBox1 & "", Sheet1.[f:f])
- ar(l + 1, 6) = Application.SumIfs(Sheet1.[g:g], Sheet1.[a:a], ComboBox2 & "", Sheet1.[c:c], ComboBox1 & "")
- ar(l + 2, 6) = Application.SumIf(Sheet1.[c:c], ComboBox1 & "", Sheet1.[g:g])
- [a6].Resize(l + 2, 6) = ar
- End Sub
复制代码 |