Userform formatted as Currency

Dan Swartz

Board Regular
Joined
Apr 17, 2020
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Not sure if i can explain this well enough but I'll try. I have a userform for making payments on an invoice. You enter the invoice number, search and it brings up all the necessary info. There are 4 textboxes that are Currency, so I used the following code to format the text boxes. if no payments have been entered, my code works great. but if i want to go look at an invoice or if they are splitting payments and i want to enter another payment. the currency format goes away. I tried to use "Change" instead of "AfterUpdate" and if I do that, it will not let me enter my values correctly. For example, if I want to enter 250, it will enter 2.01. I have attached some pictures to help

In the picture called "initial customer payment", you can see I pressed the tab key after I entered the amount of the first payment.
In the picture called "Second Customer Payment", you can see what it looks like after I entered the invoice and searched for it. It displays the first payment as just a number. not currency.


VBA Code:
Private Sub PayAmt_AfterUpdate()
    PayAmt.Value = Format(PayAmt.Value, "$#,##0.00")
End Sub
 

Attachments

  • Initail Customer Payments.jpg
    Initail Customer Payments.jpg
    93.7 KB · Views: 8
  • Second Customer Payments.jpg
    Second Customer Payments.jpg
    105.1 KB · Views: 7

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
FWIW, AfterUpdate works for me as long as there is another control on the form that focus can be set to when I hit the ENTER key. You could also backstop it with the double click event.

VBA Code:
Private Sub PayAmt_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.PayAmt
        .Value = Format(.Value, "$#,##0.00")
    End With
End Sub
 
Upvote 0
FWIW, AfterUpdate works for me as long as there is another control on the form that focus can be set to when I hit the ENTER key. You could also backstop it with the double click event.

VBA Code:
Private Sub PayAmt_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.PayAmt
        .Value = Format(.Value, "$#,##0.00")
    End With
End Sub
I tried this and it doesn't work the way I want. I don't want to have to double click the cell for it to show as currency. I tried some of the other options. And I guess I don't know how to write those. but i want it to not be tied to something special so no matter who enters an invoice, they don't have to use the down arrow, enter or dbl click. Are there any other options?
 
Upvote 0
I found the answer. I added PayAmt.Value = Format(PayAmt.Value, "$#,##0.00") at the end of the search button which gives me the proper operation.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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