How do i make a variable part of a formula

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
 
D

Dave Peterson

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
 
A

AlfD

Hi!

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

Al
 
Top