ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using variable in formula (https://www.excelbanter.com/excel-programming/427068-using-variable-formula.html)

Erik

Using variable in formula
 
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?

Dave Peterson

Using variable in formula
 
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



Erik wrote:

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?


--

Dave Peterson


All times are GMT +1. The time now is 07:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com