TextBox on a userform - format to currency & percent

T

Terry

I have a userform with a textbox named Amount & another one named Rate is
there a way to format these textboxs as Currency and Percent?
Thanks Terry
 
D

Dave Peterson

There is no edit mask that you could apply, but you could change the format each
time you leave the textbox.

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If IsNumeric(.Value) Then
.Value = Format(.Value, "$#,##0.00")
Else
'keep them in the textbox
Cancel = True
Beep
End If
End With
End Sub

If you to allow the users to hit the cancel key (if you have one) with an
invalid entry in the textbox, then make sure that cancel key has its
..takefocusonclick property set to false.
 
T

Terry

Thanks Dave Works great - Terry

Dave Peterson said:
There is no edit mask that you could apply, but you could change the format each
time you leave the textbox.

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If IsNumeric(.Value) Then
.Value = Format(.Value, "$#,##0.00")
Else
'keep them in the textbox
Cancel = True
Beep
End If
End With
End Sub

If you to allow the users to hit the cancel key (if you have one) with an
invalid entry in the textbox, then make sure that cancel key has its
..takefocusonclick property set to false.
 

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