Home » excel » excel vba – Added ' when writing formula in VBA

excel vba – Added ' when writing formula in VBA

Posted by: admin May 14, 2020 Leave a comment

Questions:
Range("C18").Select
ActiveCell.FormulaR1C1 = "='Raw Data'!A2"

When I add this to the VBA an extra ‘ is added around the A2, how can I fix this to not do that?

How to&Answers:

Use:

ActiveCell.Formula = “=’Raw Data’!A2”

Answer:

You can try with a slightly different approach:

Dim FormulaRng As Range

Set FormulaRng = Sheets("Raw Data").Range("A2")

Range("C18").Formula = "=" & FormulaRng.Address(False, False, xlA1, xlExternal)

Note: you don’t need to Select the cell, and later on use ActiveCell.FormulaR1C1, you can use Range("C18").FormulaR1C1