I have a piece of VBA code like this
'Cell A1's value is G4
varName = Range("A1").Value
Range("C2").Formula = "='Sheet2'!" & varName
What I'm trying to do is write this formula Sheet2!G4 within cell C2. Essentially, I guess I'm trying to achieve an indirect.
But when i run it, C2's formula appears like this:
'Sheet2'!'G4'
It also shows an error. I'm assuming this is because of G4 appearing in quotes when the formula is written in the cell. How can I remove this? How can I change the string varName to a range type? Or is there any other workaround for this?
'Cell A1's value is G4
varName = Range("A1").Value
Range("C2").Formula = "='Sheet2'!" & varName
What I'm trying to do is write this formula Sheet2!G4 within cell C2. Essentially, I guess I'm trying to achieve an indirect.
But when i run it, C2's formula appears like this:
'Sheet2'!'G4'
It also shows an error. I'm assuming this is because of G4 appearing in quotes when the formula is written in the cell. How can I remove this? How can I change the string varName to a range type? Or is there any other workaround for this?
Last edited: