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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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