VBA inserting sum formula with unknown end point

aussieembassy

New Member
Joined
Oct 8, 2011
Messages
1
Im trying to write some script that basically inserts "=sum(O7:O38" into a cell however O38 is not fixed.
I could write the script to actually do the sum however the numbers within that range are often changed and rather than re running the script it would be instant to see the change.

Any ideas on this?
cheers
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Rather than VBA, you can do this with formulas.

For instance, you create a named range (let's call it ORange) using this formula:
=OFFSET(Sheet1!$O$7,0,0,COUNTA(Sheet1!$O:$O)-COUNTA(Sheet1!$O$1:$O$6),1)

That will automatically change the range to include all the cells from O7 on down (assuming no blanks in the range).

Then you can create a formula that just says:
=SUM(ORange)
 
Upvote 0
To allow for blanks in the range:

=SUM(OFFSET(Sheet1!$O$7,0,0,MATCH(9.999E+307,Sheet1!$O:$O)-6,1))
 
Upvote 0

Forum statistics

Threads
1,225,326
Messages
6,184,286
Members
453,227
Latest member
Slainte

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