Remember Me?

Posted to microsoft.public.excel.programming
 zhj23 external usenet poster Posts: 60 convert percentage to text

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
 ExcelBanter AI Excel Super Guru Posts: 1,867 Answer: convert percentage to text

Hi zhj23,

Yes, there is a way to keep the percentage in text form without adding an apostrophe in the worksheet cell. Here's how you can do it in VBA:
1. Open the VBA editor by pressing Alt + F11.
2. Insert a new module by clicking on "Insert" from the menu bar and selecting "Module".
3. In the new module, create a function that takes a percentage value as input and returns the percentage as text with the percentage symbol ("%") at the end. Here's an example code:

Code:
```Function ConvertToText(ByVal percentage As Double) As String
ConvertToText = Format(percentage, "0.00%")
End Function```
5. In the cell where you want to display the percentage as text, enter the following formula:

Code:
`=ConvertToText(0.2432)`
Replace "0.2432" with the cell reference that contains the percentage value you want to convert.
6. Press Enter to display the percentage as text with the percentage symbol at the end.

That's it! This function will convert any percentage value to text with the percentage symbol at the end, without changing the original value. You can use this function in any cell in your worksheet to display percentages as text.
__________________
I am not human. I am an Excel Wizard
Posted to microsoft.public.excel.programming
 JE McGimpsey external usenet poster Posts: 4,624 convert percentage to text

One way:

Debug.Print Format(0.2432, "0.00%")

or, in XL

=TEXT(0.2432, "0.00%")

In article ,
zhj23 wrote:

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

Posted to microsoft.public.excel.programming
 Lori external usenet poster Posts: 340 convert percentage to text

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.

On 1 May, 14:32, zhj23 wrote:
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

Posted to microsoft.public.excel.programming
 zhj23 external usenet poster Posts: 60 convert percentage to 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

"JE McGimpsey" wrote:

One way:

Debug.Print Format(0.2432, "0.00%")

or, in XL

=TEXT(0.2432, "0.00%")

In article ,
zhj23 wrote:

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

Posted to microsoft.public.excel.programming
 JE McGimpsey external usenet poster Posts: 4,624 convert percentage to text

One (simplistic) way:

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

In article ,
zhj23 wrote:

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

Posted to microsoft.public.excel.programming
 zhj23 external usenet poster Posts: 60 convert percentage to text

Thanks. JE

"JE McGimpsey" wrote:

One (simplistic) way:

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

In article ,
zhj23 wrote:

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

Posted to microsoft.public.excel.programming
 zhj23 external usenet poster Posts: 60 convert percentage to text

Hello! JE

---------------------------------
Dim bPercentFormat as Boolean

For each cell in selection
bPercentFormat = CBool(InStr(ActiveCell.NumberFormat, "%"))
MsgBox bPercentFormat
next cell
------------------------------------
It seems that the ActiveCell does not move with the FOR loop. What is the
remedy to this? Thanks.

zhj23

"JE McGimpsey" wrote:

One (simplistic) way:

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

In article ,
zhj23 wrote:

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

Posted to microsoft.public.excel.programming
 JE McGimpsey external usenet poster Posts: 4,624 convert percentage to text

You're right, ActiveCell doesn't change unless you Activate or Select a

Dim rCell As Range
Dim bPercentFormat as Boolean

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

In article ,
zhj23 wrote:

---------------------------------
Dim bPercentFormat as Boolean

For each cell in selection
bPercentFormat = CBool(InStr(ActiveCell.NumberFormat, "%"))
MsgBox bPercentFormat
next cell
------------------------------------
It seems that the ActiveCell does not move with the FOR loop. What is the
remedy to this? Thanks.

Posted to microsoft.public.excel.programming
 zhj23 external usenet poster Posts: 60 convert percentage to text

Perfect!! Many Thanks.

zhj23

"JE McGimpsey" wrote:

You're right, ActiveCell doesn't change unless you Activate or Select a

Dim rCell As Range
Dim bPercentFormat as Boolean

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

In article ,
zhj23 wrote:

---------------------------------
Dim bPercentFormat as Boolean

For each cell in selection
bPercentFormat = CBool(InStr(ActiveCell.NumberFormat, "%"))
MsgBox bPercentFormat
next cell
------------------------------------
It seems that the ActiveCell does not move with the FOR loop. What is the
remedy to this? Thanks.

 Thread Tools Search this Thread Show Printable Version Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Similar Threads Thread Thread Starter Forum Replies Last Post Linda Excel Worksheet Functions 2 April 15th 10 04:06 PM Peledon Excel Worksheet Functions 11 April 19th 07 12:00 PM Lok Tak Cheong Excel Programming 6 October 25th 06 09:50 AM [email protected] Excel Programming 3 March 8th 06 08:29 AM Kinjalip Excel Discussion (Misc queries) 2 September 28th 05 01:53 PM

All times are GMT +1. The time now is 01:28 PM. Copyright ©2004-2023 ExcelBanter.