[Solved] Invalid name error in valid macro inserted formula

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

[Solved] Invalid name error in valid macro inserted formula

Post by sokolowitzky »

I have this formula in cell AD2;

I paste it with a group of other formulas, all others work exactly as desired, but this one does not calculate correctly until I re-edit it (without changing, I just press F2 and then Enter)
I think it must be because of COUNTIF, but I can not solve this. The only solution I could find to this issue(except editing content) is changing each "=" with itself (ctrl+H)
Does someone might have an idea to solve this?

Code: Select all

    ADdwa = oSheet.getcellrangebyname("AD2")
    ADdwa.formula= "=IF(AA2="&""""""&";"&""""""&";AA2+COUNTIF(AA$2:AA2;AA2)*0,01)"
Last edited by sokolowitzky on Sun Sep 23, 2018 6:44 pm, edited 3 times in total.
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Invalid name error in a valid formula, pasted by a macro

Post by Zizi64 »

Code: Select all

"&""""""&"
What is this?



Please upload a real sample file here in ODF format.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Invalid name error in a valid formula, pasted by a macro

Post by sokolowitzky »

Actually it looks like this on the spreadsheet

Code: Select all

=IF(AA2="";"";VALUE(AA2)+(COUNTIF(AA$2:AA2;AA2)*0,01)) 
Please check AD2 of Sheet1. Just click on the cell and open function wizard pop up(ctrl+f2)and press enter again.

Here I attach it . I don't want to add macro, because people who will see this later might avoid opening it. instead, I write below the macro code that it supposed to contain, so people can try themselves.

Code: Select all

Dim dizmacr
oSheet=thiscomponent.sheets(0)
    ADdwa = oSheet.getcellrangebyname("AD2")
    ADdwa.formula= "=IF(AA2="&""""""&";"&""""""&";VALUE(AA2)+(COUNTIF(AA$2:AA2;AA2)*0,01))"
end sub
Attachments
thisiswhat.ods
(8.85 KiB) Downloaded 134 times
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Invalid name error in a valid formula, pasted by a macro

Post by Zizi64 »

Code: Select all

=IF(AA2="";"";VALUE(AA2)+(COUNTIF(AA$2:AA2;AA2)*0,01))
Your formula uses "English" function names, but non-English decimal separator character. My LibreOffice 6.1.1 is adjusted to Hungarian locale (with comma dec. sep.), but with English function names in the Calc application.

I just modified the "formula" to "formulalocal" and it works!

Code: Select all

ADdwa.formulalocal= "=IF(AA2="&""""""&";"&""""""&";VALUE(AA2)+(COUNTIF(AA$2:AA2;AA2)*0,01))"
Or it works too:

Code: Select all

ADdwa.formulalocal= "=IF(AA2=" & Chr(34) & Chr(34) & ";"  & Chr(34) & Chr(34)  & ";VALUE(AA2)+(COUNTIF(AA$2:AA2;AA2)*0,01))"
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Invalid name error in a valid formula, pasted by a macro

Post by Lupp »

This should be what you needed:

Code: Select all

="IF(AA2="""";"""";VALUE(AA2)+(CONTIF(AA$2:AA2)*0.01))"
What good for?

An ordinary doublequote is represented by two subsequent doublequotes inside a string constant.
The not localised .Formula property will expect the decimal point.

(I will not again play with sheets formatted in this absurd way. Spreadsheets have cells and I want to see them.)
Attachments
sokolowitzky.ods
(11.07 KiB) Downloaded 127 times
Last edited by Lupp on Sun Sep 23, 2018 6:30 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Invalid name error in a valid formula, pasted by a macro

Post by sokolowitzky »

Mister Kovacs, i don't know if you write in this forum just for leisure. But you are doing great. I really appreciate all your help.
Thanks a lot.
@Lupp. Thanks. The reason I don't use gridlines is becaue I feel like they kill my focus. Instead I change the bckground colur in the areas I use.
Thanks for your answer.
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Invalid name error in valid macro inserted form

Post by Zizi64 »

i don't know if you write in this forum just for leisure.
Yes, it is my hobby, and it is my special method of learning - 'two in one'. ;)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Invalid name error in valid macro inserted form

Post by Lupp »

I missed to emphasise that the #NAME? error alert should always occur if an otherwise correct formula contains a numeric constant with a decimal separator not complying with the locale chosen under 'Language Settings'. This is not changed by a different language setting for the document or for cells.

For the .Formula property of a cell I would expect that the point as the decimal separator is mandatory.
(You may experiment with the .FormulaLocal property.)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply