Reference a Named Range in an Excel VBA Formula
Question details
Create a VBA formula that adds the value of a named range in one workbook to a cell in another workbook.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro needs to use the ConstantZ named range on Sheet1 in a formula in another workbook.
- Observed behavior
- The formula uses incorrect worksheet references and quotation marks.
Open both workbooks and check that ConstantZ refers to the intended cell on Sheet1. Confirm the destination workbook, worksheet, and cell where the formula should be placed.
Build an external R1C1 reference to the named range
Use this approach to add the named range's value to the cell immediately left of a specified destination cell.
FormulaR1C1 is required because RC[-1] uses R1C1 notation. The Address method generates an external reference to the cell behind ConstantZ, rather than inserting the name itself.
In Excel, open Developer > Visual Basic and open the module containing the macro.
Replace the workbook, worksheet, and cell names in this example with your own: Dim sourceWs As Worksheet Dim targetCell As Range Set sourceWs = Workbooks("Source.xlsx").Worksheets("Sheet1") Set targetCell = Workbooks("Destination.xlsx").Worksheets("Sheet2").Range("B2")
Add this line to the macro: targetCell.FormulaR1C1 = "=RC[-1]+" & sourceWs.Range("ConstantZ").Address(ReferenceStyle:=xlR1C1, External:=True) The formula adds the value in the cell to the left of B2 to the cell referenced by ConstantZ.
Run the macro from the VBA editor, then select the destination cell in Excel and inspect its formula and result.

Work with spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for an easier move between applications. The Excel VBA fix above should be applied in Microsoft Excel.

Frequently Asked Questions
Why should I use FormulaR1C1 instead of Formula?
RC[-1] is an R1C1-style reference. Assign it through Range.FormulaR1C1 and request an R1C1 external address with Address(ReferenceStyle:=xlR1C1, External:=True).
What does RC[-1] refer to?
It refers to the cell in the same row and one column to the left of the cell containing the formula. For a formula in B2, it refers to A2.
How do I find the scope of ConstantZ?
In the source workbook, open Formulas > Name Manager and find ConstantZ. Check its Scope and Refers to fields, especially if the same name exists at both workbook and worksheet scope.
When do I need to double quotation marks in a VBA formula string?
Double a quotation mark when it must appear inside a VBA string. The example uses normal quotation marks around VBA string values and lets the Address method construct the external worksheet reference.
Can I use ThisWorkbook instead of Workbooks("Source.xlsx")?
Yes, if the macro is stored in the source workbook. ThisWorkbook refers to the workbook containing the VBA code, which may differ from the active workbook.




