|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Private Sub CommandButton1_Click()
Dim i, arr, sum
If Not (Len(ComboBox1.Text) > 0 And Len(ComboBox2.Text) > 0) Then Exit Sub
ReDim sum(1 To 4)
arr = Sheets("收入明细").[a1].CurrentRegion
For i = 2 To UBound(arr, 1)
If arr(i, 3) = ComboBox1.Text And arr(i, 4) = ComboBox2.Text Then
sum(1) = sum(1) + arr(i, 6)
sum(2) = sum(2) + arr(i, 9)
sum(3) = sum(3) + arr(i, 8)
End If
Next
arr = Sheets("支出明细").[a4].CurrentRegion
For i = 2 To UBound(arr, 1)
If arr(i, 3) = ComboBox1.Text And arr(i, 4) = ComboBox2.Text Then
sum(4) = sum(4) + arr(i, 6)
End If
Next
For i = 1 To 4: Controls("TextBox" & i).Text = sum(i): Next
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
For i = 2 To 1000
ComboBox1.AddItem Sheets("查询").Range("g" & i)
ComboBox2.AddItem Sheets("查询").Range("h" & i)
Next
End Sub |
|