Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 6 of 6

Thread: Using Exit Event to Format a Text Box

  1. #1
    Join Date
    26th March 2011
    Posts
    3

    Using Exit Event to Format a Text Box

    I am trying automatically to format a number in a text box as a percentage. I am trying to use the exit event to trigger the format but it doesn't seem to do anything. Any ideas? Here is the code I wrote. The text box is called tb_fixedfee.

    VB:
    Private Sub tb_fixedfee_Exit() 
         
        tb_fixedfee.Value = Format(tb_fixedfee.Value, "0.00%") 
         
    End Sub 
    
    
    Last edited by AAE; March 26th, 2011 at 11:46. Reason: ADD CODE TAGS

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    10th June 2010
    Location
    Seattle, WA
    Posts
    451

    Re: Using Exit Event to Format a Text Box

    How about:

    VB:
    tb_fixedfee = Format(Val(tb_fixedfee), "0.00%") 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    26th March 2011
    Posts
    3

    Re: Using Exit Event to Format a Text Box

    Thanks. Actually to be more specific I can't get the exit event to trigger so no matter what is after the event it doesn't trigger. I am thinking it is something in the properties for the text box, but I am really not sure.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    19th January 2007
    Location
    South Carolina, USA
    Posts
    9,206

    Re: Using Exit Event to Format a Text Box

    Hello nrowader,

    Welcome to Ozgrid.

    While we're glad to have you on-board, please take some time to read through the Forum Rules.

    All VBA code posted in the forum must be wrapped in code tags which you omitted. I've added the tags for you this time only. Be sure to use them in future posts.

    How to use code tags

    [code]
    your code goes between these tags
    [/code]
    ----------------------------------------------------------

    There is a slight difference in the text box properties depending on whether you are using the textbox embedded into the worksheet via the Control Box controls or using the control on a user form. There is not a an Exit_Event for textbox controls embedded into the worksheet sheet (at least not in my version of Excel/VBA). However, you could use the lostfocue event.

    VB:
    Private Sub TextBox1_LostFocus() 
        With Me.TextBox1 
            .Value = Format(.Value, "0.00%") 
        End With 
    End Sub 
    
    
    If using a textbox control in the user form:

    VB:
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) 
         
        With Me.TextBox1 
            .Value = Format(.Value, "0.00%") 
        End With 
         
    End Sub 
    
    
    AAE
    ----------------------------------------------------

    Forum Rules | Message to Cross Posters | How to use Tags

  5. #5
    Join Date
    8th December 2006
    Location
    New Zealand
    Posts
    3,924

    Re: Using Exit Event to Format a Text Box

    VB:
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 
         
        With Me.TextBox1 
            If IsNumeric(.Text) Then 
                .Value = Format(.Value, "0.00%") 
            Else 
                Cancel = True 
            End If 
        End With 
         
    End Sub 
    
    

  6. #6
    Join Date
    26th March 2011
    Posts
    3

    Re: Using Exit Event to Format a Text Box

    Thanks for both ideas, that did it.

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Replies: 4
    Last Post: March 10th, 2011, 02:23
  2. Conditional Format Formula Cells In Change Event
    By jobrumo in forum EXCEL HELP
    Replies: 1
    Last Post: April 20th, 2008, 11:29
  3. Exit-Event for dymamically created Controls
    By b1022084 in forum EXCEL HELP
    Replies: 2
    Last Post: May 11th, 2006, 02:29
  4. On Enter/Exit Event - Focus
    By Dave Hawley in forum EXCEL HELP
    Replies: 1
    Last Post: November 22nd, 2004, 22:06
  5. On Enter/Exit Event - Focus
    By Ktrasler in forum EXCEL HELP
    Replies: 4
    Last Post: November 22nd, 2004, 04:55

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
  •  
porno