convert percentage to text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

when a percentage is converted to text, it always gives the decimal form.
e.g. 24.32% will become 0.2432. How can I keep "24.32%" in text form? I guess
there is a better way to do it in VBA than to first add an apostrophe in the
worksheet cell.

Many thanks.

zhj23
 
One way is to copy and paste as text...

First copy with office clipboard (edit menu), then format the cell
range as text and then click the paste icon followed by edit > paste
special > text.
 
Thanks for the valuable helps.

Bcos some of my data are in simple numeric (eg 2.63) and some are in
percentage numeric form (eg 24.32%), obviuosly I dont want to convert 2.63 to
263.00%.

Question: how can I evaluate in VBA whether a cell is in simple numeric or
percentage numeric form?

zhj23
 
One (simplistic) way:

Dim bPercentFormat As Boolean
bPercentFormat = CBool(InStr(Range("A1").NumberFormat, "%"))
MsgBox bPercentFormat
 
Thanks. JE

JE McGimpsey said:
One (simplistic) way:

Dim bPercentFormat As Boolean
bPercentFormat = CBool(InStr(Range("A1").NumberFormat, "%"))
MsgBox bPercentFormat
 
Hello! JE

Following your advice, I did the following (extracted codes)
---------------------------------
Dim bPercentFormat as Boolean

For each cell in selection
bPercentFormat = CBool(InStr(ActiveCell.NumberFormat, "%"))
MsgBox bPercentFormat
next cell
 
You're right, ActiveCell doesn't change unless you Activate or Select a
range. Use your range object variable instead:

Dim rCell As Range
Dim bPercentFormat as Boolean

For each rCell In Selection
bPercentFormat = CBool(InStr(rCell.NumberFormat, "%"))
MsgBox bPercentFormat
Next rCell
 
Perfect!! Many Thanks.

zhj23

JE McGimpsey said:
You're right, ActiveCell doesn't change unless you Activate or Select a
range. Use your range object variable instead:

Dim rCell As Range
Dim bPercentFormat as Boolean

For each rCell In Selection
bPercentFormat = CBool(InStr(rCell.NumberFormat, "%"))
MsgBox bPercentFormat
Next rCell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top