[Solved] Set a range with 1 parameter as variable

Creating a macro - Writing a Script - Using the API

[Solved] Set a range with 1 parameter as variable

Postby maximlee » Mon Jan 15, 2018 4:01 am

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   Expand viewCollapse view
oSheet.getCellByPosition(myCol, j).formula = "=SUM("N" & j & ":T" & j)"


What's the right syntax?
Last edited by maximlee on Tue Jan 16, 2018 2:02 am, edited 2 times in total.
Libre Office 5.2 on Windows 7
maximlee
 
Posts: 2
Joined: Mon Jan 15, 2018 3:39 am

Re: Set a range with 1 parameter as variable

Postby FJCC » Mon Jan 15, 2018 5:47 am

The code would be like
Code: Select all   Expand viewCollapse view
oSheet.getCellByPosition(myCol, j).formula = "=SUM(N" & j & ":T" & j & ")"

but j cannot be 0 because cell addresses like N0 are not valid.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7269
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set a range with 1 parameter as variable

Postby UnklDonald418 » Mon Jan 15, 2018 6:54 am

Try
Code: Select all   Expand viewCollapse view
oSheet.getCellByPosition(myCol, j).setFormula ( "=SUM(N" & j & ":T" & j & ")")
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1214
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby maximlee » Tue Jan 16, 2018 2:01 am

Thanks, this is it (at least the 1st entry).
Libre Office 5.2 on Windows 7
maximlee
 
Posts: 2
Joined: Mon Jan 15, 2018 3:39 am


Return to Macros and UNO API

Who is online

Users browsing this forum: im.eugen and 5 guests