How do i make a variable part of a formula

  • Thread starter Thread starter grrarrgh
  • Start date Start date
G

grrarrgh

Say I have some vba code that looks like:


ActiveCell.Range("A1:B5").Select
Selection.FormulaArray = _
"=LINEST(R[1]C[-3]:R[5]C[-3],R[1]C[-2]:R[5]C[2],TRUE,TRUE)"

Let's say that I am looping over some variable i, and would someho
like to insert that variable into the code:

Selection.FormulaArray = _
"=LINEST(R[1]C[*i*]:R[5]C[*i+1
],R[1]C[-2]:R[5]C[2],TRUE,TRUE)"

Obviously, I can't simply insert the i's in there -- what instea
should i do?

thank
 
Selection.FormulaArray = _
"=LINEST(R[1]C[" & i & "]:R[5]C[" & i+1 & "],R[1]C[-2]:R[5]C[2],TRUE,TRUE)"

(I think I got the right spot!)

grrarrgh < said:
Say I have some vba code that looks like:

ActiveCell.Range("A1:B5").Select
Selection.FormulaArray = _
"=LINEST(R[1]C[-3]:R[5]C[-3],R[1]C[-2]:R[5]C[2],TRUE,TRUE)"

Let's say that I am looping over some variable i, and would somehow
like to insert that variable into the code:

Selection.FormulaArray = _
"=LINEST(R[1]C[*i*]:R[5]C[*i+1*
],R[1]C[-2]:R[5]C[2],TRUE,TRUE)"

Obviously, I can't simply insert the i's in there -- what instead
should i do?

thanks
 
Hi!

What's wrong with putting the *i* in the formula? After all, that'
fundamental to loops.

Al
 

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