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

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
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,215,381
Messages
6,124,614
Members
449,175
Latest member
Anniewonder

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