what am I doing wrong here

tonyBruckner

New Member
Joined
Apr 18, 2002
Messages
21
I'm trying to write a simple formula into cell A2 to get the value 3 to appear in it...

if cell A1 = 3

Sub writeFormula
Dim cellValue as string

range("A1").select
cellValue = activeCell.address
range("A2").select
activeCell.FormulaR1C1 = "=" & cellValue

End Sub

The hover looks right but I get an alert that disqualifies the last line. I've tried several variations...

What is the correct syntax?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You are using the R1C1 formula property but not an R1C1 formula.
Code:
activeCell.[COLOR="Red"]FormulaR1C1[/COLOR] = "=" & cellValue

Amend to:
Code:
activeCell.Formula = "=" & cellValue
 
Upvote 0
Not sure if you are just investigating syntax, but you generally do not need to select things in vba to work with them. Your whole macro could be replaced with
Code:
Sub writeFormula()
    Range("A2").Formula = "=A1"
End Sub
Or if you wanted to use R1C1 notation
Code:
Sub writeFormula()
    Range("A2").FormulaR1C1 = "=R[-1]C"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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