VBA & Macro Problems

How to Insert Variables into R1C1 and A1 VBA Strings in Excel

Phi Hung VoPhi Hung Vo Nov 2, 2026 869 views

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.

How to Insert Variables into R1C1 and A1 VBA Strings in Excel
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.
Before you start

Ensure you have the Developer tab enabled in your Excel ribbon and a basic understanding of variable declaration in VBA.

Solution 1Recommended

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.

1
Declare your variables

Define your row and column variables at the start of your sub, for example: 'Dim targetRow As Long' and 'Dim scanCol As Long'.

2
Assign integer values

Set the numerical values for your row and column variables (e.g., targetRow = 5, scanCol = 2).

3
Construct the R1C1 string

Use the syntax: targetString = "R" & targetRow & "C" & scanCol. This code dynamically evaluates to 'R5C2'.

Use the Ampersand Operator to Concatenate Variables for R1C1 Notation
Handling Double Quotation Marks: If you need an actual double quote inside your generated string, you must type two double quotes in a row ("") within the literal string section.
Advanced VBA Support

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. 1. Download and Install: Download WPS Office for free from the official website and follow the installation wizard.
  2. 2. Open your Spreadsheet: Launch WPS Spreadsheet and open your existing macro-enabled workbook (.xlsm).
  3. 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. 4. Edit and Run Code: Modify your string concatenation logic and run your updated macros directly within the editor.
Fully compatible with Microsoft Excel formats, including macro-enabled .xlsm and .xls files.Built-in VBA editor allows you to write, debug, and execute complex variable strings.Lightweight application that loads fast and consumes minimal system resources.Free to use with a familiar tabbed interface, ensuring a seamless migration experience.
QA img-9

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.