Both relative and absolute references in Subtotal

Gus68

New Member
Joined
Feb 13, 2011
Messages
11
Hi All,

Is it possible to use both relative and absolute cell references in a subtotal macro?

We're trying to create a subtotal within our macro that uses cell E3 as the absolute and the cell above the active cell as the relative reference. I just can't work out the syntax (if it's even possible!!)

I get a compile error when I use the following:-
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,"E3":R[-1]C)"

Can anybody point me in the right direction? And apologies if this has been posted previously - none of my searches returned a hit.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You can't mix A1 and R1C1 references. Maybe

Code:
... = "=SUBTOTAL(9, R3C:R[-1]C)"
 
Upvote 0
Or:
Code:
activecell.Formula = "=SUBTOTAL(9,E3:" & Left(Cells(1, activecell.Column).Address(1, 0), InStr(1, Cells(1, activecell.Column).Address(1, 0), "$") - 1) & activecell.Row-1 & ")"
 
Upvote 0
Thank you both for your replies!

I was 99% sure that you wouldn't be able to use both absolute and relative but thought I'd ask the question just in case.

Shg's suggestion does the job simply enough for what we need.. thanks!!
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

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