[Solved] Change percent in cell to value*100

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
alf50
Posts: 129
Joined: Sun Jun 13, 2010 2:55 pm

[Solved] Change percent in cell to value*100

Post by alf50 »

I Need a Macro to change Percent in Cell to Value*100.
If I have a Percent in a cell, like in cell A1 '25.1% (note the single quote in front, and in the next column (cell B1) type =Value(A1)*100, everything works as you would expect, cell B1 displays as 25.1 when I try a macro to do the same thing, nothing works. What am I doing wrong??

Code: Select all

for II = 120 to 270
	oDoc=ThisComponent 
	oSheet = oDoc.Sheets.getByName("Calcs")
	oCell = oSheet.getCellByposition(3,II) '$D$II+1
	Pct = oCell.String
	
'	If II > 123 then goto CPTV4:
'	if Left(Pct,1) = "'" then oCell.String = Right(Pct,LEN(Pct)-1)

	oCell.String = Value(Pct)*100
	
'	Msgbox "Pct Value= " & oCell.String
next II
Last edited by MrProgrammer on Wed Apr 24, 2024 7:32 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Need a Macro to change Percent in Cell to Value*100

Post by Villeroy »

Find/Replace % with nothing and you get the decimal cell value.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Zizi64
Volunteer
Posts: 11364
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Need a macro to change percent in cell to value*100

Post by Zizi64 »

'25.1%
The "apostrophe - number - percent unit" combo seems a STRING imported from a .csv, .tsv file. In this case you must import the data properly before, or you must remove the apostrophe sign by the macro.
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
Zizi64
Volunteer
Posts: 11364
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Need a macro to change percent in cell to value*100

Post by Zizi64 »

Code: Select all

oCell.String = Value(Pct)*100
There is not a function named "Value()" in the StarBasic. The existing one is the "Val()"

The "Value()" is a Cell Function. And you can not call the spreadsheet Cell Functions such simple way. (is is possible, but it is more diffcoult.)

Or is it your own user defined "Value()" function?
Last edited by Zizi64 on Tue Mar 26, 2024 8:20 am, edited 2 times in total.
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
Zizi64
Volunteer
Posts: 11364
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Need a macro to change percent in cell to value*100

Post by Zizi64 »

Code: Select all

for II = 120 to 270
	oDoc=ThisComponent 
	oSheet = oDoc.Sheets.getByName("Calcs")
Why you call the same ThisComponent and Sheets.getByName("Calcs") functions so many times (inside the for cycle)? It is enough to call it once.
The StarBasic has a low speed anyway. Dol not slowener it more.
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.
Post Reply