Sum with R1C1 notation and variable

chriscorpion786

Board Regular
Joined
Apr 3, 2011
Messages
108
Office Version
  1. 365
Platform
  1. Windows
Hi ,

Can anyone tell me how to sum a range with R1C1 notation using a variable to go two cells left from the active cell, for eg:

Activecell.value = "=sum(rc[-2]:rc[-1] ' this works perfectly but when I use a variable I cannot make it work...

Activecellvalue = "=sum(rc & "[- lastcol +4 ]" :rc[-1] 'this does not work.

Multiple examples would be great if possible.

Thank you in advance.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try:
Code:
Activecell.value = "=sum(rc[- " & lastcol & " +4 ]:rc[-1]"
This will only work if lastcol is a number.
Dan
 
Upvote 0
Hi Dan,

I tried the same , dosent work...

activecell.value = "=sum(rc [- " & lastcol & " +4]:rc[-1])"

lastcol is a number by the way. It throws up the error : Application defined or object defined error.
 
Upvote 0
Try this.
Code:
ActiveCell.FormulaR1C1 = "=SUM(RC[" & -lastCol + 4 & "]:RC[-1])"
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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