Using variable in formula

E

Erik

Public Sub test()
hv = Range("aa1")
Cells(i + 5, 23).Offset(step, 0).Formula = "=+RC[-1]*52*hv"
End Sub

Range("aa1") contains the value 269.1. The value in RC[-1] is 3758.7.

The cell in position 5,23++ does not recognize hv as a number but just shows
"hv" with the rest of the formula. How can I fix this?
 
D

Dave Peterson

You're using R1C1 reference style. So use .FormulaR1C1.

And you don't need that leading + in the formula:

Cells(i + 5, 23).Offset(step, 0).FormulaR1C1 = "=RC[-1]*52*" & hv


Public Sub test()
hv = Range("aa1")
Cells(i + 5, 23).Offset(step, 0).Formula = "=+RC[-1]*52*hv"
End Sub

Range("aa1") contains the value 269.1. The value in RC[-1] is 3758.7.

The cell in position 5,23++ does not recognize hv as a number but just shows
"hv" with the rest of the formula. How can I fix this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top