Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Percentage format | Excel Worksheet Functions | |||
Format Percentage | Excel Discussion (Misc queries) | |||
Format percentage as a decimal | Excel Discussion (Misc queries) | |||
Percentage format | New Users to Excel | |||
Percentage format | Excel Worksheet Functions |