ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   cell referencing with variables (https://www.excelbanter.com/excel-programming/384863-cell-referencing-variables.html)

Liesbeth

cell referencing with variables
 
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

Vergel Adriano

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


Liesie

cell referencing with variables
 
Thank you!

"Vergel Adriano" wrote:

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



All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com