userform number formatting

  • Thread starter Thread starter Rick Sanderson
  • Start date Start date
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
 
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.
 
Back
Top