PC Review


Reply
Thread Tools Rate Thread

convert percentage to text

 
 
=?Utf-8?B?emhqMjM=?=
Guest
Posts: n/a
 
      1st May 2007
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
 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      1st May 2007
One way:

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

or, in XL

=TEXT(0.2432, "0.00%")

In article <F675F5F4-C229-496E-9DD1-(E-Mail Removed)>,
zhj23 <(E-Mail Removed)> 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

 
Reply With Quote
 
Lori
Guest
Posts: n/a
 
      1st May 2007
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 <z...@discussions.microsoft.com> 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



 
Reply With Quote
 
=?Utf-8?B?emhqMjM=?=
Guest
Posts: n/a
 
      2nd May 2007
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 <F675F5F4-C229-496E-9DD1-(E-Mail Removed)>,
> zhj23 <(E-Mail Removed)> 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

>

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      2nd May 2007
One (simplistic) way:

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


In article <EF677B07-4A0F-4043-9262-(E-Mail Removed)>,
zhj23 <(E-Mail Removed)> wrote:

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

 
Reply With Quote
 
=?Utf-8?B?emhqMjM=?=
Guest
Posts: n/a
 
      3rd May 2007
Thanks. JE

"JE McGimpsey" wrote:

> One (simplistic) way:
>
> Dim bPercentFormat As Boolean
> bPercentFormat = CBool(InStr(Range("A1").NumberFormat, "%"))
> MsgBox bPercentFormat
>
>
> In article <EF677B07-4A0F-4043-9262-(E-Mail Removed)>,
> zhj23 <(E-Mail Removed)> wrote:
>
> > Question: how can I evaluate in VBA whether a cell is in simple numeric or
> > percentage numeric form?

>

 
Reply With Quote
 
=?Utf-8?B?emhqMjM=?=
Guest
Posts: n/a
 
      3rd May 2007
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
------------------------------------
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 <EF677B07-4A0F-4043-9262-(E-Mail Removed)>,
> zhj23 <(E-Mail Removed)> wrote:
>
> > Question: how can I evaluate in VBA whether a cell is in simple numeric or
> > percentage numeric form?

>

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      3rd May 2007
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

In article <4F1372E0-374E-46B5-A0D0-(E-Mail Removed)>,
zhj23 <(E-Mail Removed)> wrote:

> 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
> ------------------------------------
> It seems that the ActiveCell does not move with the FOR loop. What is the
> remedy to this? Thanks.

 
Reply With Quote
 
=?Utf-8?B?emhqMjM=?=
Guest
Posts: n/a
 
      3rd May 2007
Perfect!! Many Thanks.

zhj23

"JE McGimpsey" wrote:

> 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
>
> In article <4F1372E0-374E-46B5-A0D0-(E-Mail Removed)>,
> zhj23 <(E-Mail Removed)> wrote:
>
> > 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
> > ------------------------------------
> > It seems that the ActiveCell does not move with the FOR loop. What is the
> > remedy to this? Thanks.

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a percentage to an hour Annabelle Microsoft Excel Misc 2 17th Dec 2010 12:59 AM
Convert percentage into margin Linda Microsoft Excel Worksheet Functions 2 15th Apr 2010 04:06 PM
Convert Percentage to total number of NPT Days =?Utf-8?B?UGVsZWRvbg==?= Microsoft Excel Worksheet Functions 11 19th Apr 2007 12:00 PM
Convert Percentage to number steer.tim@gmail.com Microsoft Excel Programming 3 8th Mar 2006 07:29 AM
Convert Percentage to Text =?Utf-8?B?S2luamFsaXA=?= Microsoft Excel Misc 2 28th Sep 2005 01:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 AM.