View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vergel Adriano Vergel Adriano is offline
external usenet poster
 
Posts: 857
Default cell referencing with variables

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

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


"Liesbeth" wrote:

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