1

I am a new beginner of VBA and I am trying to write a sumif function in each row of column D but will change the criteria and sum column range for each row until the last value of the criteria column.

For example: start from row 4, the first sum & criteria range will be 4:4, the second one will be 4:5 and the third one will be 4:6, etc.

I want the answer should be looked like the example below but it only show 8 for those row with "x" in column A.

Dose anyone have any idea to make it show as column D in the example below.

Worksheet:

column A B C D E
4      x   1 1
5      x   2 3
6      y   1  
7      y   3 
8      z   4 
9      x   5 8

Code:

llistrow = ThisWorkbook.Worksheets(Source).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row - 1
For i = 4 To llistrow Step 1
    revisedbudget1314 = Application.WorksheetFunction.SumIf( _
        Arg1:=ThisWorkbook.Worksheets(Source).Range(Cells(4, 1), Cells(i, 1)), _
        Arg2:="x", _
        Arg3:=ThisWorkbook.Worksheets(Source).Range(Cells(4, 3), Cells(i, 3)))
Next i 

1 Answer 1

0

Enter this formula in cell D1

=IF(A1="x", SUMIF(A$1:A1, "=x", C$1:C1), "")

and just multiply it for the other cells of column D (select D1 and double click on the small rectangle in lower right corner)

Please use better tags for your questions (e.g. excel or spreadsheet) so more people can look at them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.