Format number in text box as typed

brianburen

New Member
Joined
Aug 24, 2010
Messages
44
I have a userform with a text box

the user enters any number from 4.500 to 16.000

I want the box to format the text entered to have the 3 decimal places as its typed.


How do i do this?
I've tried the putting .... format (textbox1.text, ("0.000"))
in the textbox1_change()

but it doesnt work
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
In the AfterUpdate event you could put

Code:
TextBox1.Text = Format(Val(TextBox1.Text,), "0.000")

note that TextBox1.Text is always a string and that
Format("abc", "0.000") = "abc" and
Format("1.2", "0.000") = "1.2"
 
Upvote 0
Try this
Code:
Private Sub TextBox1_AfterUpdate()
    With TextBox1
        .Text = Format(Val(.Text) / 1000, "0.000")
    End With
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    If Not Chr(KeyAscii) Like "[0-9]" Then
        KeyAscii = 0
    End If
End Sub
 
Upvote 0
If i have a userform with say 20 textboxes on it, do i have to do this for every one of them? or is there a way to group them?
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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