Excel VBA Textbox Number Format

Michaels

Active Member
Joined
Apr 2, 2009
Messages
404
Hello !

I am trying to change the format of textbox1 on userform1 as below:


Private Sub Textbox1_Change()

Textbox1.Text = Format$(TB1.Text, "0.00")

End Sub
The above code is not working.

What I need is like this:

When the userform initializes, the number format (or the numbers) in textbox on userform1 is 0.000. When my cursor reaches inside the textbox, and I type a number, say 25000, and press tab to move to the next textbox, the number in textbox1 changes to 25,000

You help is highly appreciated in this regard.

Thank you
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi,
see if this approach helps:

Code:
Private Sub TextBox1_AfterUpdate()
With Me.TextBox1

    If IsNumeric(.Value) Then .Value = Format(.Value, "0.00")

End With
End Sub


Private Sub UserForm_Initialize()
With Me.TextBox1
    .Value = 0
    .Value = Format(.Value, "0.00")
End With
End Sub

Adjust code to meet specific project need as required.

Dave
 
Last edited:
Upvote 1
Hi,
see if this approach helps:

Code:
Private Sub TextBox1_AfterUpdate()
With Me.TextBox1

    If IsNumeric(.Value) Then .Value = Format(.Value, "0.00")

End With
End Sub


Private Sub UserForm_Initialize()
With Me.TextBox1
    .Value = 0
    .Value = Format(.Value, "0.00")
End With
End Sub

Adjust code to meet specific project need as required.

Dave

Thank you for your help Dave.

Now, when I press tab (to move to next textbox), it does this: 25000.00 (not 25,000.00 <-- this format is required)

Thank you
 
Upvote 1
Thanks Dave, it works now as I changed it to:

Code:
Private Sub Reg8_AfterUpdate()
With UserForm1.Reg8


    If IsNumeric(.Value) Then .Value = Format(.Value, "#,##0.00")


End With
End Sub

Thank you very much for your help. So nice of you :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,541
Messages
6,120,110
Members
448,945
Latest member
Vmanchoppy

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