Userform Textbox Currency Format Problems

D

Dunce in SC

I am having trouble getting a textbox to format user input in currency
When I use the following code

Private Sub TextBoxgencost_Change()
TextBoxgencost.Text = Format(TextBoxgencost.Text, "Currency")
End Sub

Or
Private Sub TextBoxgencost_Change()
TextBoxgencost.Text = Format(TextBoxgencost.Text, "$###,###,##")
End Sub

It will only allow me to enter 4 numbers and then behaves as a counter
and increases the last digit by one .

Thanks for the help
 
T

Tom Ogilvy

Change fires every time you enter a character, so when you start getting the
results of the format, things don't work right

Private Sub TextBoxgencost_Change()
Dim sStr as String
sStr = trim(TextBoxgencost.Text)
sStr = Application.Substitute(Application. _
Substitute(sStr,",",""),"$","")
if Isnumeric(sStr) then
TextBoxgencost.Text = Format( _
TextBoxgencost.Text, "$###,###,##")
End if
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top