PDA

View Full Version : Solved: how to display a special character in a message box?



Simon Lloyd
01-14-2007, 11:26 AM
Hi all, i have some code that displays a message box and gives results from certain cells, my problem arises when i try to display the value of Sheets("Stats").Range("D2"), the cell is formatted as % and i would like to display the value in the message box as % i.e 9.25%, however it displays something like 9.251342635+1E. Anyone know how to cure this?

Regards,
SImon

Ken Puls
01-14-2007, 11:38 AM
Try:
MsgBox "Your pecentage is " & Format(Worksheets("Stats").Range("D2"), "0.00%")

HTH,

Simon Lloyd
01-14-2007, 11:55 AM
Thanks a lot Ken, i tried this Format(Sheets("Stats").Range("D2"),"%0") but couldnt get it to work properly, yours worked fine!

Regards,
SImon

Bob Phillips
01-14-2007, 12:03 PM
MsgBox "Your pecentage is " & Worksheets("Stats").Range("D2").Text

Ken Puls
01-14-2007, 12:31 PM
Interesting, Bob. I've always specified the format in code.

Maybe I jus tdon't trust that my users won't change the format on the cell on me... LOL!

Simon Lloyd
01-14-2007, 01:03 PM
MsgBox "Your pecentage is " & Worksheets("Stats").Range("D2").Text
I dont know why i didn't think of that Bob, i messed around with alsorts to get it work, then searched the net and came up with this link http://groups.google.co.uk/group/microsoft.public.excel.misc/browse_thread/thread/96857801754ec785/627f28b96a144e6f%23627f28b96a144e6f its one you posted to in 2004 but i couldnt get your example to work (the one i posted back in reply to Ken), i guess it's 'cos im tired and was to close to it!, working nights is a killer!

Regards to both,
Simon

Bob Phillips
01-14-2007, 02:32 PM
I'm ubiquitous, you can't avoid me.

You need Format to format a variable or a cell that you don't know in advance what it's format is. But you mentioned that the cell was already formatted as percentage, so you can use the range's Text property.

Ken Puls
01-14-2007, 04:44 PM
I'm ubiquitous, you can't avoid me.

Alas, many have tried... :p

Simon Lloyd
01-15-2007, 04:31 AM
I'm ubiquitous, you can't avoid me.I guess omnipresence does have euphoric properties as you seem to be quite pleased at the fact!

Regards,
Devoted Pupil

Bob Phillips
01-15-2007, 06:11 AM
Not pleased, not dis-pleased, just accepting things in the teleological sense, in that purpose carries no imputation of causation.

Simon Lloyd
01-15-2007, 06:50 AM
Lol

Pragmatic as always!

Cyberdude
01-15-2007, 11:17 AM
i tried this


VBA:

Format(Sheets("Stats").Range("D2"),"%0")


but couldnt get it to work properly Maybe your problem is that you used "%0" instead of "0%".

Simon Lloyd
01-15-2007, 01:00 PM
Thanks for the reply 'Dude!