0
我在Sheet1中有表格。我可以总结某个国家的所有数字数据。 但是,我只想总结相同日期的数字。 我有ComboBox的日期。因此,例如,如果我选择7月1日,它只会在七月添加这些号码1.根据另一列中的另一个标准在列中添加一组数字值
我的期望,如果我选择7月1日结果如下: 美国24 巴西56 加拿大68
这里是我的截图:screenshot
mycode的:
Private Sub ComboBox1_Change()
Dim a As Long
Dim b As Long
Dim c As Long
Dim lastrow As Long
a = 0
b = 0
c = 0
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 3) = "America" Then
a = Cells(i, 4) + a
ElseIf Cells(i, 3) = "Brazil" Then
b = Cells(i, 4) + b
ElseIf Cells(i, 3) = "Canada" Then
c = Cells(i, 4) + c
End If
Next i
'Range("A16") = a
txtAmerica.Value = a
txtBrazil.Value = b
txtCanada.Value = c
End Sub
Private Sub UserForm_Initialize()
ComboBox1.List = Sheets("Sheet1").Range("G1:G10").Value
End Sub
非常感谢。这就是我真正想做的事。 –