userform number formatting

R

Rick Sanderson

Hi,
having entered a number into a textbox in a userform how does one then
format it to have 2 decimal places?
its not too important as they are formatted in the cells they end up entered
into, it would just make it easier on the eye.

Rick
 
D

Dave Peterson

Tom Ogilvy just posted this for someone else. It does a little more than you
ask, but may be what you want <bg>.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(TextBox1.Value) Then
If Len(Trim(TextBox1.Value)) = 1 Then
TextBox1.Value = Format(CLng(TextBox1.Value), "0000")
Else
MsgBox "Single Digit Numbers only"
TextBox1.Value = ""
Cancel = True
End If
Else
MsgBox "Entry must be numeric and single digit"
TextBox1.Value = ""
Cancel = True
End If
End Sub

But you can see that the Format() stuff is the part that does the, er,
formatting.
 

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