Page 1 of 1

[Solved] Change percent in cell to value*100

Posted: Mon Mar 25, 2024 10:01 pm
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

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

Posted: Mon Mar 25, 2024 10:09 pm
by Villeroy
Find/Replace % with nothing and you get the decimal cell value.

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

Posted: Tue Mar 26, 2024 6:30 am
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.

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

Posted: Tue Mar 26, 2024 6:42 am
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?

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

Posted: Tue Mar 26, 2024 6:47 am
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.