VBA Sum from a specific cell to a relative cell

Finalfight40

Active Member
Joined
Apr 24, 2018
Messages
273
Office Version
  1. 365
Platform
  1. Windows
Hi All

I am looking for a little bit of advice for a formula in VBA.

I created a macro but while testing it i noticed that this line of code was not going to be correct for all situations.

Code:
ActiveCell.FormulaR1C1 = "=SUM(RC[-10]:RC[-1])"

I would like it to sum from B3 to RC[-1] but of course just replacing RC[-10] with B3 would just be too easy.

Also if it matters, the formula does get copied down the column later on where B3 would then need to change to C3, D3, E3 etc.

Thank you for any advice.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Also if its possible, sum from the 2nd column on the active row to RC[-1] because i know that further on in my macro i have to do the same thing but for a column. This would change because of the filters applied before the macro runs and so sometimes the table would finish on Column N but other times might finish on Column AX for example.

Would be a very good thing to know so that i can adapt for this project and future projects.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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