Putting in "=sum" function in VBA

vkats

New Member
Joined
Mar 2, 2022
Messages
2
Office Version
  1. 365
Platform
  1. MacOS
Hi Guys,

I'm trying to make my active cell input the sum function but I keep getting different errors, I started up by recording a macro which set my range according to my selection:

Selection.FormulaR1C1 = "=SUM(R[-58]C:R[-1]C)"

But I need it to sum a dynamic range which will change every time I run the macro so I created a simple loop to determine the offset amount and put it into an integer "RowCounter" then put in that integer into the same sum function:

Selection.FormulaR1C1 = "=SUM(R[RowCounter]C:R[-1]C)"

"RowCounter" is -58 in this case, but it doesn't work, could you please suggest a way to make this work please.

Thank you!!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi & welcome to MrExcel.
How about
VBA Code:
Selection.FormulaR1C1 = "=SUM(R[" & RowCounter & "]C:R[-1]C)"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

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