Excel UserForm VBA code for currency with 2 decimal places

mar9el

New Member
Joined
Mar 29, 2016
Messages
5
Good morning!

I am trying to create a userform on excel to function as a ledger. I have a text box for an amount and would like to format for currency with 2 decimal places.

Private Sub txtAmount_Change()

txtAmount.Value = Format(txtAmount, "$#,##0.00")

End Sub

It seems to be stuck to show only $#.00 (see attached). Could it be, I am supposed to do something with the txtAmount properties?

1666203016263.png
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
What about this.
VBA Code:
Private Sub txtAmount_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.txtAmount.Value = Format(Me.txtAmount.Value, "$0.00")
End Sub
 
Upvote 0
What about this.
VBA Code:
Private Sub txtAmount_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.txtAmount.Value = Format(Me.txtAmount.Value, "$0.00")
End Sub
Thank you, I am getting a syntax error on this line:

txtAmount_Exit(ByVal Cancel As MSForms.ReturnBoolean)
 
Upvote 0
Thank you, I am getting a syntax error on this line:

txtAmount_Exit(ByVal Cancel As MSForms.ReturnBoolean)

I tested the code and it works for me. Make sure the code goes in the form's code, module and that a text box with the name "txtAmount" exits on the userform. Also, what version of Excel are you using?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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