Results 1 to 5 of 5

Thread: [RESOLVED] Format user input as currency

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Resolved [RESOLVED] Format user input as currency

    When a user enters data in a spread sheet the spread sheet can be formatted so that (say) 36 appears as $36.00, or 25/3/9 appears as 25-Mar-09.

    What I want to do is the same sort of thing in a User Form, so that when the user has entered a number and tabs to the next field the number looks like currency.

    I have several label captions that take the user input and remove the tax to provide a nett value, or that add bank fees which I have been able to format. (This form sits in an excel file.)

  2. #2
    Lively Member
    Join Date
    May 2009
    Posts
    67

    Re: Format user input as currency

    try the FormatCurrency Vb function:

    Code:
    TextBox1.Text = ".1"
    MsgBox FormatCurrency(TextBox1.Text) 'Should be $0.10
    TextBox1.Text = "5"
    MsgBox FormatCurrency(TextBox1.Text) 'Should be $5.00
    TextBox1.Text = "10000000"
    MsgBox FormatCurrency(TextBox1.Text) 'Should be $10,000,000.00
    There's different optional parameters you can pass, listed on the MS site I linked above.
    Last edited by nanoinfinity; Jun 4th, 2009 at 09:14 AM. Reason: added better example

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Format user input as currency

    be careful of using the formatted strings, in the textboxes, if you want to do any calculations using the values
    vb Code:
    1. text1 = "25/3/9"
    2. text1 = format(text1, "dd-mmm-yy")
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Location
    Townsville, Qld, Australia
    Posts
    135

    Re: Format user input as currency

    I've been thinking about this one some more: I don't think that what I want to do is possible in Excel. (I was thinking in terms of a number of mainframe applications I've met where the user input is not formatted until it is used somewhere later in the program.) The type of formatting I want can be done in Access, with an input mask. So I'll mark this one as resolved - just as soon as I find out how to do that!

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] Format user input as currency

    was thinking in terms of a number of mainframe applications I've met where the user input is not formatted until it is used somewhere later in the program.
    of course you can do like that
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width