How to Insert Variables into R1C1 and A1 VBA Strings in Excel
Question details
The user needs to combine row and column variables with text to dynamically create Excel cell references in both R1C1 and A1 notations using VBA.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Writing a VBA macro that requires dynamic cell referencing using string concatenation.
- Observed behavior
- The VBA script returns a literal string (e.g., printing the variable's name instead of its value) because the variables are incorrectly placed inside the quotation marks.
Ensure you have the Developer tab enabled in your Excel ribbon and a basic understanding of variable declaration in VBA.
Use the Ampersand Operator to Concatenate Variables for R1C1 Notation
Correctly combine literal text strings and variables by placing variables outside of the quotation marks.
In VBA, anything placed inside double quotation marks is treated strictly as literal text. To evaluate a variable, you must terminate the string, use the ampersand (&) concatenation operator, insert the variable, and then resume the string.
Define your row and column variables at the start of your sub, for example: 'Dim targetRow As Long' and 'Dim scanCol As Long'.
Set the numerical values for your row and column variables (e.g., targetRow = 5, scanCol = 2).
Use the syntax: targetString = "R" & targetRow & "C" & scanCol. This code dynamically evaluates to 'R5C2'.

Generate A1 Notation Using the Cells Address Property
Use the built-in Cells property to automatically convert numerical row and column variables into an A1 style reference.
Write and Execute Macros Seamlessly with WPS Spreadsheet
WPS Office fully supports VBA macros, allowing you to run, edit, and troubleshoot your R1C1 and A1 string concatenation scripts effortlessly within a familiar environment.
- 1. Download and Install: Download WPS Office for free from the official website and follow the installation wizard.
- 2. Open your Spreadsheet: Launch WPS Spreadsheet and open your existing macro-enabled workbook (.xlsm).
- 3. Access the VBA Editor: Navigate to the Developer tab on the top ribbon and click on 'Visual Basic' to open the VBA environment.
- 4. Edit and Run Code: Modify your string concatenation logic and run your updated macros directly within the editor.

Frequently Asked Questions
Why is my VBA variable printing its name instead of its value?
This happens when the variable name is enclosed within double quotation marks. VBA treats everything inside the quotes as literal text. To fix this, close the quotes, add an ampersand (&), and place the variable completely outside the quotes.
How do I include actual double quotation marks in a VBA string?
To insert a literal double quote inside a string, type two consecutive double quotation marks ("") within the quoted text. Alternatively, you can concatenate Chr(34) into your string.
How can I dynamically change column letters in A1 notation using VBA?
Instead of building complex strings with column letters, it is much easier to use the Cells(row, column).Address property. This method takes integer values for both row and column and automatically generates the correct A1 formatted cell reference without requiring letter conversion.




