formating textboxes in userforms

jcg

Board Regular
Joined
Jul 12, 2002
Messages
156
again, a real easy question for most of you but can anyone tell me how to format the textboxes in a userform as a % number format versus a currency or date etc.

Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I hate saying the word "impossible" on this board as it's usually a good way to get shot in the face, but I'm pretty sure this is one of those situations!

As far as I know, you can't do it.
You can restrict what people enter, even down to the keystrokes (http://www.mrexcel.com/board/viewtopic.php?topic=14368&forum=2) but formatting is out.
I think you have to have code in the userform to check the validity of what has been entered.
Could you use If statements in your code using the IsNumeric or IsDate or whatever else functions to do the same job?

What do the rest of the gurus say??

Rgds
AJ
 
Upvote 0
Howdy folks, if your textbox is named textbox1, you can use the BeforeUpdate event (code stored in userform module) to format your text entry. It will convert your number (i.e., .2 = 20%)<pre>
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox1.Value = Format(Me.TextBox1.Value, "0.00%")
End Sub</pre>

Similar procedure for other types of formatting. Hope this helps.

Edit: A workaround for the % conversion looks like:<pre>
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox1.Value = Format(Me.TextBox1.Value / 100, "0.00%")
End Sub</pre>
_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-07-15 17:16
 
Last edited by a moderator:
Upvote 0
I hate saying the word "impossible" on this board as it's usually a good way to get shot in the face, but I'm pretty sure this is one of those situations!

BANG! Right between the eyes!

nice one Nate!
 
Upvote 0

Forum statistics

Threads
1,222,697
Messages
6,167,702
Members
452,132
Latest member
Steve T

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top