How to write a VBA code to select certain rows based on certain conditions
Hi houstoncity2004,
Try this :
'------------------
Sub SommeIF()
With Worksheets("Sheet1")
Group1 = Application.SumIf(.Range("A1:A10"), "=" & 1, .Range("B1:B10"))
Group2 = Application.SumIf(.Range("A1:A10"), "=" & 2, .Range("B1:B10"))
End With
End Sub
'------------------
Salutations!
a écrit dans le message de om...
I need help to write part of a VBA code in Excel. I am trying to do
calculations on rows that meeting certain requirements, but I do not
know how to established that in VBA. I know that if I use the
worksheet itself, I can do something like SUMIF() function. But, when
I put the same function in the VBA editor, it returns error. A simple
version of my data:
Group No Member No Amount spent
1 1 10
1 2 3
1 3 4
2 1 6
2 2 1
3 1 12
4 1 3
4 2 1
I am trying to calculate the total amount spent based on the group no.
FOr example, how much does group no.1 spent, how much does group no.2
spent, etc.
I appreciate anybody who can help me with this. Thank you very much.
|