Using a single variable in a FormulaR1C1

citroendealer

New Member
Joined
Sep 27, 2016
Messages
13
This is a simplification of my problem. A1 has a number and B1 is selected. When I run this code it results in an error, why?

Code:
Sub test()
 Dim x As Single
 x = 0.5
 ActiveCell.FormulaR1C1 = "=RC[-1]*" & x
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Provided A1 contains a number and B1 is the active cell, the code does not produce an error for me. Rather, it inserts the following formula into B1:

=A1*0.5
 
Upvote 0
When it wants to run the line with the formulaR1C1 i get "Run-time error '1004': Application-defined or object-defined error"
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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