[Solved] Countif written in macro returns zero value

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sanjyot
Posts: 4
Joined: Wed Oct 24, 2018 1:47 pm

[Solved] Countif written in macro returns zero value

Post by sanjyot »

I have written a formula in the macro for spreadsheet to calculate as below . This works fine when i paste it in the cell but returns zero when I put it in the macro. Can anybody please explain what is going wrong?
oSheetKeys.getCellByPosition(10,i+2) ="=countif($C$3:C3;C3)"
Last edited by Hagar Delest on Thu Nov 01, 2018 5:50 pm, edited 1 time in total.
Reason: tagged solved
OpenOffice 3.1
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: countif written in macro returns zero value

Post by RusselB »

Welcome to the forums.
While I admit that my knowledge of macros is almost nil, I have to wonder about the fact that you have the countif formula inside quotation marks.
Have you tried oSheetKeys.getCellByPosition(10,i+2) = countif($C$3:C3;C3)
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: countif written in macro returns zero value

Post by FJCC »

The object returned by

Code: Select all

oSheetKeys.getCellByPosition(10,i+2)
refers to the whole cell, all of its properties and methods. If you want to set the Formula of the cell, do this

Code: Select all

oSheetKeys.getCellByPosition(10,i+2).Formula ="=countif($C$3:C3;C3)"
Judging from the i in your code, you are doing this in a loop. The result will be to set every cell to have the exact same formula. Is that what you want?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
sanjyot
Posts: 4
Joined: Wed Oct 24, 2018 1:47 pm

Re: countif written in macro returns zero value

Post by sanjyot »

Thanks FJCC. oSheetKeys.getCellByPosition(10,i+2).Formula ="=countif($C$3:C3;C3)" This worked. I was putting. value instead of Formula.
OpenOffice 3.1
sanjyot
Posts: 4
Joined: Wed Oct 24, 2018 1:47 pm

Re: countif written in macro returns zero value

Post by sanjyot »

Yes..its a loop I need to have the formula incremented except $C$3. I have used this. oSheetKeys.getCellByPosition(10,i+2).Formula ="=countif(Keys.$C$2" + ":Keys.C" + (i+2) + ";Keys.C" + (i+2+1) + ")". Although it works if you have an easier way and simpler please do suggest. I am new to macros
OpenOffice 3.1
Post Reply