VBA enter R1C1 formula in cell including string

fbohlandt

New Member
Joined
Sep 17, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi all

I have a simple VBA script that is writing formulas to Excel. In Excel, the formula will look something like this:

="'"&A3&"'"

Note the high commas bracketing the cell reference.

I am not sure what to do in VBA to combine cell reference and string. Here is what I have (which is not really working):

VBA Code:
Sub Quote()

    ThisWorkbook.ActiveSheet.Range("H3").FormulaR1C1 = Chr(39) & "=R3C1" & Chr(39)

End Sub

Ideally, I would like to keep the R1C1 cell reference style.

Thanks in advance
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Based on your example it looks as simple as adding the 'high commas' to the R1C1 reference in the code, although it is not entirely clear what the final outcome should be.
VBA Code:
ThisWorkbook.ActiveSheet.Range("H3").FormulaR1C1 = Chr(39) & "='R3C1'" & Chr(39)
 
Upvote 0
Would suggest to switch to the Formula property, as in ...
VBA Code:
ThisWorkbook.ActiveSheet.Range("H3").Formula = "=""'""&A3&""'"""
 
Upvote 0
Solution

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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