autoformat number in textbox

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

autoformat number in textbox

Post by sal21 »

I have a NEWGIAC textbox in userform of vba Excel.

Is possible during the digit in NEWGIAC autoformat the number in , "#,##0.00" (?)

note:
I just use this code to accept only number in tetxtbox.

Code: Select all

Private Sub NEWGIAC_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If InStr(1, Me.NEWGIAC.Text, ".") > 0 And KeyAscii = Asc(".") Then
        KeyAscii = 0
        Exit Sub
    End If
    Select Case KeyAscii
        Case Asc("0") To Asc("9"), Asc(".")
        Case Else
            KeyAscii = 0
    End Select
End Sub


Last edited by sal21 on 27 Jun 2014, 08:52, edited 1 time in total.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: autoformat number in textbox

Post by Rudi »

Maybe something like this?

Code: Select all

Private Sub NEWGIAC_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.NEWGIAC.Value = Format(Me.NEWGIAC.Value, "#,##0.00")
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.