Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variable in formula
Variables should be kept out of the string and combined using &..
Public Sub test() hv = Range("aa1") Cells(i + 5, 23).Offset(step, 0).Formula = "=+RC[-1]*52*" & hv End Sub If this post helps click Yes --------------- Jacob Skaria "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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variable in formula
I get runtime error 1004.
"Jacob Skaria" wrote: Variables should be kept out of the string and combined using &.. Public Sub test() hv = Range("aa1") Cells(i + 5, 23).Offset(step, 0).Formula = "=+RC[-1]*52*" & hv End Sub If this post helps click Yes --------------- Jacob Skaria "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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variable in formula
make sure that you have
OPTION EXPLICIT heading the code module ensure that your variables are both correctly dimensioned and that they have values. I ran your test, adding a value for i, and it was ok Public Sub test() i = 5 ' test to make code work hv = Range("aa1") Cells(i + 5, 23).Offset(step, 0).Formula = "=+RC[-1]*52*" & hv End Sub error 1004 usualy referes to a range not being found "Erik" wrote: I get runtime error 1004. "Jacob Skaria" wrote: Variables should be kept out of the string and combined using &.. Public Sub test() hv = Range("aa1") Cells(i + 5, 23).Offset(step, 0).Formula = "=+RC[-1]*52*" & hv End Sub If this post helps click Yes --------------- Jacob Skaria "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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
formula containing a formula-dependent variable - how? | New Users to Excel | |||
Using a variable in a formula | Excel Programming | |||
variable in a formula | Excel Programming | |||
Using a second variable within a formula... | Excel Discussion (Misc queries) | |||
Variable in a Formula | Excel Programming |