Page 1 of 1

[Solved] Set a range with 1 parameter as variable

Posted: Mon Jan 15, 2018 4:01 am
by maximlee
Hi,
I am trying to insert a formula to every row, calculating sum of several cells in the same row. By the moment of automatic insertion I will only know columns, while row numbers would be variable, so I need to add something like:

[A0] = [SUM(N0:T0)]
[A1] = [SUM(N1:T1)]

Code: Select all

oSheet.getCellByPosition(myCol, j).formula = "=SUM("N" & j & ":T" & j)"
What's the right syntax?

Re: Set a range with 1 parameter as variable

Posted: Mon Jan 15, 2018 5:47 am
by FJCC
The code would be like

Code: Select all

oSheet.getCellByPosition(myCol, j).formula = "=SUM(N" & j & ":T" & j & ")"
but j cannot be 0 because cell addresses like N0 are not valid.

Re: Set a range with 1 parameter as variable

Posted: Mon Jan 15, 2018 6:54 am
by UnklDonald418
Try

Code: Select all

 oSheet.getCellByPosition(myCol, j).setFormula ( "=SUM(N" & j & ":T" & j & ")")

Re: [Solved] Set a range with 1 parameter as variable

Posted: Tue Jan 16, 2018 2:01 am
by maximlee
Thanks, this is it (at least the 1st entry).