cell referencing with variables

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

Guest

I need some help. I need to populate a formula where the rows and columns
are variable.

My first formula works. My second formula gets hung up on the variable "x".
Note ColumnNumbers 1 and 2 always change, but never less than 3 and 5
respectively, x is always columnnumber1 + 1

Cells(i, ColumnNumber1).FormulaR1C1 = "=SUM(RC2:RC[-1])"
' Cells(i, ColumnNumber2).FormulaR1C1 = "=SUM(RC[-x]:RC[-1])"

Is there another way of doing this formula? I am fairly new at VBA.

Thank you,
Liesbeth
 
Assuming the value of x is being set somewhere else in the code,

Cells(i, ColumnNumber2).FormulaR1C1 = "=SUM(RC[-" & x & "]:RC[-1])"
 
Thank you!

Vergel Adriano said:
Assuming the value of x is being set somewhere else in the code,

Cells(i, ColumnNumber2).FormulaR1C1 = "=SUM(RC[-" & x & "]:RC[-1])"


Liesbeth said:
I need some help. I need to populate a formula where the rows and columns
are variable.

My first formula works. My second formula gets hung up on the variable "x".
Note ColumnNumbers 1 and 2 always change, but never less than 3 and 5
respectively, x is always columnnumber1 + 1

Cells(i, ColumnNumber1).FormulaR1C1 = "=SUM(RC2:RC[-1])"
' Cells(i, ColumnNumber2).FormulaR1C1 = "=SUM(RC[-x]:RC[-1])"

Is there another way of doing this formula? I am fairly new at VBA.

Thank you,
Liesbeth
 
Back
Top