Inserting a Range Into A Formula Using a Variable

username142

New Member
Joined
May 30, 2014
Messages
23
I've declared the variable 'Action' as a string, and I am assigning a range to it based upon the contents of a cell. For example, the first one being assigned is C52:CY55. And I'm trying to insert that range into the formula below using the variable name, but it's not working. In the formula that's inserted to the active cell, the range is posting as $AZ:$AZ:'CY55' instead. Does anyone have any suggestions?

Code:
ActiveCell.Formula = _
            "=SUM(INDEX('" & CurrentSheet & "'!" & Action & ",,COLUMN()+Summary!RC[-1]-2))"
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Try inserting 'Action.Address' instead of just 'Action' The Excel formula is looking for a cell reference, not a variabele value.
 

username142

New Member
Joined
May 30, 2014
Messages
23
Thanks for the suggestion. I'm getting "Compile error: invalid qualifier" with that change.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,299
Office Version
  1. 365
Platform
  1. Windows
You can't mix A1 and R1C1 notation.

This part of your formula uses R1C1

Summary!RC[-1]-2

and in your post you appear to be saying Action is a string variable with a range reference in A1 notation.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,530
Messages
5,659,358
Members
418,498
Latest member
nattynat

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
Top