View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.fr.excel
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default How to write a VBA code to select certain rows based on certain conditions

First, while I assume you have a reason for wanting to do this in VBA,
I'd feel remiss if I didn't suggest you look at Pivot Tables instead (see

http://peltiertech.com/Excel/Pivots/pivotstart.htm

for an intro).

You can use the SUMIF function in VBA:

Dim dResult As Double
dResult = Application.SumIf(Range("A1:A10"), "=1", Range("C1:C10"))



In article ,
) wrote:

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.