Tricky summation query

bat18

Board Regular
Joined
Mar 29, 2010
Messages
89
I need a formula that will sum up to a blank cell. Is there such a forumla or macro that will do that??

Something along the lines of typing a formula into D30 which would mean the following

IF (A30<100, sum(C30 upwards to next blank cell), 0).

A macro may be required for this so any help would be great

Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
This macro should work. Just place your cursor in the cell you want to put your sum in and run:

Code:
Sub MyFormulaPopulation()
 
    Dim myCurRow As Long
    Dim myPrevBlankRow As Long
    
    myCurRow = ActiveCell.Row
    myPrevBlankRow = Cells(myCurRow, "C").End(xlUp).Row
    Cells(myCurRow, "D").Formula = "=IF(A" & myCurRow & "<100,SUM(C" & myPrevBlankRow & ":C" & myCurRow & "),0)"
 
End Sub
 
Upvote 0
I need a formula that will sum up to a blank cell. Is there such a forumla or macro that will do that??

Something along the lines of typing a formula into D30 which would mean the following

IF (A30<100, sum(C30 upwards to next blank cell), 0).

A macro may be required for this so any help would be great

Thanks

Maybe:

Code:
Sub bat18()

If Range("A30").Value < 100 Then

    Range("C30").Select
    Do While ActiveCell <> ""
        ActiveCell.Offset(-1).Select
    Loop
       
   Range("D30").Value = WorksheetFunction.Sum(Range(ActiveCell, Range("C30")))
    
    

End If
 
Upvote 0
I don't think you want to hard code in row reference of 30 in your code, or else it will only work for row 30!

I also got the impression that the wanted the entire IF statement as part of the resulting formula which gets written to the cell, which is why I did it that way. Otherwise, it won't be dynamic (in case the value in column A ever changes).
 
Upvote 0
I don't think you want to hard code in row reference of 30 in your code, or else it will only work for row 30!

I also got the impression that the wanted the entire IF statement as part of the resulting formula which gets written to the cell, which is why I did it that way. Otherwise, it won't be dynamic (in case the value in column A ever changes).

You're right. I had been working on the thread and for what it's worth, I just posted it anyway. Yours is much better.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top