Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Text format as percentage

I have a userform that I use multiple times. When this form loads the first
time, I use the following code to format the text to a percentage:

Private Sub TextBox21_afterupdate()
If TextBox21.Value < "" Then
TextBox21 = TextBox21 / 100
With UserForm1.TextBox21
.Text = Format(.Text, "0.00%")
End With
End If

however, if I ever focus back on that textbox, and then focus off, it
crashes the code. how would I add code that basically says "if the number is
already in percentage format, ignore the rest of this code"? (or is there a
better way to write the above code to fix this error all together?)

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Text format as percentage

Try replacing the first line after the If statement with this one instead
(leave the rest of your code as is)...

TextBox21 = Replace(TextBox21, "%", "") / 100

--
Rick (MVP - Excel)


"Shane" wrote in message
...
I have a userform that I use multiple times. When this form loads the
first
time, I use the following code to format the text to a percentage:

Private Sub TextBox21_afterupdate()
If TextBox21.Value < "" Then
TextBox21 = TextBox21 / 100
With UserForm1.TextBox21
.Text = Format(.Text, "0.00%")
End With
End If

however, if I ever focus back on that textbox, and then focus off, it
crashes the code. how would I add code that basically says "if the number
is
already in percentage format, ignore the rest of this code"? (or is there
a
better way to write the above code to fix this error all together?)

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
Percentage format dpal Excel Worksheet Functions 1 February 4th 10 02:14 PM
Format Percentage hmaze Excel Discussion (Misc queries) 9 March 19th 08 07:28 PM
Format percentage as a decimal BSAT Student Excel Discussion (Misc queries) 2 October 20th 05 09:48 PM
Percentage format Randy New Users to Excel 2 May 11th 05 05:06 PM
Percentage format f16pilot Excel Worksheet Functions 3 October 29th 04 09:47 PM


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

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

About Us

"It's about Microsoft Excel"