+ Reply to Thread
Results 1 to 6 of 6

Userform Textbox Number Formatting VBA

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    Owensboro, KY
    MS-Off Ver
    Excel 2010
    Posts
    10

    Question Userform Textbox Number Formatting VBA

    I have a textbox on a userform that needs to automatically format to #########-#####
    I am using this to add the "-" after the 9th digit, however some of my users are pasting the data into the text box with a dash already in the number, creating a second dash.
    Please Login or Register  to view this content.
    How can I change this so it doesn't matter if the user enters a dash or not, it only shows the dash at the 10th position and if the user only enters 9 numbers to add five zeros at the end? Formatting should look like this:

    if entered 123456789 should change to 123456789-00000
    if entered 12345678912345 should change to 123456789-12345
    if entered 123456789-12345 should stay 123456789-12345

  2. #2
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Userform Textbox Number Formatting VBA

    This is untested, but can you remove/replace an existing dash if it exists before adding your own?

    Please Login or Register  to view this content.
    But I see you code is only checking if the Length is equal to 9. What if it is greater than 9?

  3. #3
    Registered User
    Join Date
    08-09-2012
    Location
    Owensboro, KY
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Userform Textbox Number Formatting VBA

    Replace isn't working here, when I compile the code it says Argument not optional

  4. #4
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Userform Textbox Number Formatting VBA

    sorry, try this.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-09-2012
    Location
    Owensboro, KY
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Userform Textbox Number Formatting VBA

    Unfortunately this doesn't fix my problem. With the above, when the user types the data in and types a dash, it shows two dashes in the text box. Also, if the user pastes the info into the text box the data does not update or change.

  6. #6
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Userform Textbox Number Formatting VBA

    I think you need to post a sample of what, or more really when you want to check for the extra dash and remove it.

    If you want the dash removed when they type in the userform you likely need the code in an after update like this below

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Conditional formatting userform textbox based on textbox value
    By kidwispa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2014, 08:28 AM
  2. [SOLVED] Help formatting a textbox in a userform.
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2013, 10:13 AM
  3. [SOLVED] Userform TextBox Problem... formatting code clears data instead of formatting
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2012, 11:00 AM
  4. [SOLVED] Help formatting a textbox for a userform
    By dougwild in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-19-2012, 06:47 AM
  5. Userform Textbox Formatting
    By LSM1604 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-01-2010, 04:42 AM
  6. Userform Textbox Formatting
    By lilsnoop in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-02-2009, 02:53 PM
  7. Formatting a textbox within a userform
    By steve_c in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2008, 02:43 AM

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