Using variables in RCs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I would like to have the following formula contain a variable if
possible. For instance, instead of having "RC[-10]", I would like to have
"RC[-j]" where "j" is a variable. Is there a way to do this?

ActiveCell.FormulaR1C1 =
"=IF((RC[-10]+RC[-4])>0,RC[-10]/(RC[-10]+RC[-4]),na())"

Thanks,
Mike.
 
To make the debugging easier, I usually do it like this:

Dim s As String
j = 10
k = 4

s = "=IF((RC[##]+RC[@@])>0,RC[##]/(RC[##]+RC[@@]),na())"
s = Replace(s, "##", Format(-j))
s = Replace(s, "@@", Format(-k))

This way, I find it easier to ensure I have the basic formula correct.
 

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

Back
Top