Sum using Variable

F

Fatz

Hi-

The following code will sum the 14 rows above the row I am in. I want
to replace the -14 below with a variable (i). How do I code the below
to work with a variable?

ActiveCell.FormulaR1C1 = "=SUM(R[-14]C:R[-1]C)"

Thank You!

Chris
 
T

Tom Hutchins

Try

ActiveCell.FormulaR1C1 = "=SUM(R[" & i & "]C:R[-1]C)"

Remember, i must be a negative whole number in this example.

Hope this helps,

Hutch
 
N

Norman Jones

Hi Chris,

To replace the negative constant (-14) with a varible, try:

Dim i As Long

i = -14

ActiveCell.FormulaR1C1 = "=SUM(R[" & i & "]C:R[-1]C)"


By the way, I believet that your formula
sums the 13 cells below the actice cell,
rather than the 14 cells above it.
 
F

Fatz

Hi Chris,

To replace the negative constant (-14) with a varible, try:

    Dim i As Long

    i = -14

    ActiveCell.FormulaR1C1 = "=SUM(R[" & i & "]C:R[-1]C)"

By the way, I believet that your formula
sums the 13 cells below the actice cell,
rather than the 14 cells above it.

---
Regards.
Norman




The following code will sum the 14 rows above the row I am in.  I want
to replace the -14 below with a variable (i).  How do I code the below
to work with a variable?
ActiveCell.FormulaR1C1 = "=SUM(R[-14]C:R[-1]C)"
Thank You!
Chris- Hide quoted text -

- Show quoted text -

Thanks to everyone! It works great.....

Chris
 

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

Top