Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old May 1st 07, 02:32 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2006
Posts: 60
Default 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

  #2   Report Post  
Old May 1st 07, 02:36 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 4,624
Default 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

  #3   Report Post  
Old May 1st 07, 04:51 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Sep 2006
Posts: 340
Default 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



  #4   Report Post  
Old May 2nd 07, 01:47 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2006
Posts: 60
Default 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


  #5   Report Post  
Old May 2nd 07, 04:18 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 4,624
Default 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?



  #6   Report Post  
Old May 3rd 07, 01:28 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2006
Posts: 60
Default 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?


  #7   Report Post  
Old May 3rd 07, 02:50 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2006
Posts: 60
Default convert percentage to text

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 ,
zhj23 wrote:

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


  #8   Report Post  
Old May 3rd 07, 04:08 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 4,624
Default convert percentage to text

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 ,
zhj23 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.

  #9   Report Post  
Old May 3rd 07, 04:22 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Nov 2006
Posts: 60
Default convert percentage to text

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 ,
zhj23 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert percentage into margin Linda Excel Worksheet Functions 2 April 15th 10 04:06 PM
Convert Percentage to total number of NPT Days Peledon Excel Worksheet Functions 11 April 19th 07 12:00 PM
Extract a percentage from a text Lok Tak Cheong Excel Programming 6 October 25th 06 09:50 AM
Convert Percentage to number [email protected] Excel Programming 3 March 8th 06 07:29 AM
Convert Percentage to Text Kinjalip Excel Discussion (Misc queries) 2 September 28th 05 01:53 PM


All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Copyright 2004-2022 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017