+ Reply to Thread
Results 1 to 7 of 7

format a TextBox on a userform

  1. #1
    Registered User
    Join Date
    10-17-2008
    Location
    Kinston, NC
    Posts
    20

    format a TextBox on a userform

    I am creating a userform in vba with textboxes. Input (from user) into the textbox is copied to a worksheet in the workbook.

    I one text box users will need to type numbers and in another they will need to type letters.

    Can the textbox be formatted so it will only allow a number?
    Can the text box be formatted to only allow text?

    I have attached the workbook.

    Thanks,
    Randy
    Attached Files Attached Files
    Last edited by randyvann; 10-20-2008 at 05:10 PM. Reason: Problem solved!

  2. #2
    Forum Contributor
    Join Date
    04-11-2005
    Location
    London
    Posts
    259
    What about the following?
    Please Login or Register  to view this content.
    You can use similar logic using IsText() for your second textbox.

    Martin
    Martin Short

  3. #3
    Registered User
    Join Date
    10-17-2008
    Location
    Kinston, NC
    Posts
    20
    Thanks, the number formatting works great. How about the letter formatting?

  4. #4
    Forum Contributor
    Join Date
    04-11-2005
    Location
    London
    Posts
    259
    I thought that was going to be easy, but it's anything but. The IsText function, doesn't work as it assumes that everything in the textbox is text; even numeric data.

    There are probably heaps of better solutions and I'm sure (and hope) that someone will make a better suggestion, but here is my solution.

    My logic is as follows:
    1. Dimension a variable as numeric so it can't contain text.
    2. Try to store the contents of the textbox in the numeric variable
    3. If it can be stored, it is a number
    4. If it can't be stored, then the error handling will kick in and the err.number will equal 13 not 0. i.e. it must have been text.

    Please Login or Register  to view this content.
    HTH
    Martin

  5. #5
    Registered User
    Join Date
    10-17-2008
    Location
    Kinston, NC
    Posts
    20
    Works like a charm. I did remove the "MsgBox "You entered text" portion as it is not needed.

    Thanks a million!

  6. #6
    Forum Contributor
    Join Date
    04-11-2005
    Location
    London
    Posts
    259
    Actually, a simpler way - DOH! - would be to reverse the logic on the original and remove the "Not"
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-11-2005
    Location
    London
    Posts
    259
    Glad to help
    Martin

+ 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. Current Userform TextBox
    By Zappd in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 05-19-2008, 05:30 PM
  2. textbox to Cell date format issues
    By Panic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2008, 03:06 AM
  3. Userform textbox link issue
    By chris100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-05-2008, 02:45 PM
  4. Copy a Textbox value from a userform?
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2007, 07:48 AM
  5. Textbox invisible on userform
    By Jilt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-20-2007, 07:41 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