+ Reply to Thread
Results 1 to 5 of 5

Formatting a VBA Form as Currency

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-29-2008
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    127

    Formatting a VBA Form as Currency

    This has to be VBA 101... but....

    can I format a textbox in a VBA form that when I input 500 and go to the next box, it formats it as a currency and displays "$500.00"

    i'm sure it's super easy, i just don't know the steps.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I'd put
    TextBox1.Text = Format(TextBox1.Text, "$#,##0.00")
    in the After_Update routine.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    06-29-2008
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    127
    ok, here it is, i was thinking it would be much easier, but i can't seem to get it.

    there are 6 categories that i need to format as a currency, they are:


    Assigned Fee
    Billing Rate
    Tax Strategies Fee
    Transactional Tax Fee
    Business Valuation Fee
    Website Fee

    here's the workbook, i'm pretty lost.
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Use the textbox exit event to format the contents

    Private Sub txtAsgnFee_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me
    If Len(.txtAsgnFee.Value) > 0 Then .txtAsgnFee.Value = Format(txtAsgnFee.Value, _
        "Currency")
    End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I just learned that you can use format names in a Format function -- my Excel lesson for the day, thanks, Roy.

    You could generalize Roy's approach a tad:
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        FormatCurrency Me.TextBox1
    End Sub
    
    Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        FormatCurrency Me.TextBox2
    End Sub
    
    Sub FormatCurrency(ctl As MSForms.TextBox)
        If Len(ctl.Value) Then ctl.Value = Format(ctl.Value, "Currency")
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1