Unable to have VBA insert a relative reference then make part of it absolute.

eMHDfNhuwLhQCzJ

New Member
Joined
May 4, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
When I run this VBA code:
ActiveCell.FormulaR1C1 = "=SUM(RC[-1]:R[14]C[-1])"

It places the following formula in the active cell:
=SUM(H19:H33)

I need to modify that VBA code so that it whatever the active cell is it makes the first reference absolute.

If I was clicked inside C19 it should produce the formula =SUM($B$19:B33)
So if I was clicked inside F19 it should produce the formula =SUM($E$19:E33)

So far I can't figure out how to do this. Can anyone help me figure it out?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try:
VBA Code:
With ActiveCell
    .Formula = "=SUM(" & .Offset(, -1).Address & ":" & .Offset(14, -1).Address(0, 0) & ")"
End With
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
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