+ Reply to Thread
Results 1 to 18 of 18

Restrict entries in textboxes on userform

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Restrict entries in textboxes on userform

    Hello everyone
    I have a userform with textboxes ( 1 to 13 ) which should be restriected in entries as follows

    First, Just the letter "A" is allowed in entry and no other letters or words or any text allowed ..just the letter "A" (Capital case)
    -----
    Second, each text box should be restricted by minimum and maximum value , as for the minimum for all the textboxes would be 0 but as for the maximum value related to cells in yellow (In Sheets("Data"))
    For example : range("R12") has the value 50 >> So the textbox1 should be from 0 to 50 only and if it is less than 0 or greater than 50 , a message box would be appear to pay the user's attention ...

    AC12 is related to Textbox2
    AN12 is related to Textbox3
    AZ12 is related to Textbox4
    BA12 is related to Textbox5
    BN12 is related to Textbox6
    BO12 is related to Textbox7
    CA12 is related to Textbox8
    CL12 is related to Textbox9
    CM12 is related to Textbox10
    DO12 is related to Textbox11
    DZ12 is related to Textbox12
    EK12 is related to Textbox13

    If possible I need to deal with all the textboxes all together that have the same conditions (I mean textboxes 1 & 2 & 3 & 7 & 8 & 10 & 11 & 12 & 13 have the same maximum value .. so if possible to deal with them all together)

    Hope it is clear
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Restrict entries in textboxes on userform

    Hi there Yasser!

    I'm really in a hurry but I'll be back later. First thing though, for you to put values in a text box use the .Text property.
    Please Login or Register  to view this content.
    , not
    Please Login or Register  to view this content.
    Be right back!
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    Thanks a lot Mr. Bulina for reply
    I will wait for your reply
    The request is concerned how to restrict the entries of these textboxes (textbox1 to textbox13) ..some textboxes are similar in conditions of restriction

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    Any help in this topic please?

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    If you add this code to your user form's code module, that should work.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    That's amazing Mr. mikerickson
    I just need to emphasize that the letter "A" would be allowed along with the minumum and maximum values
    I mean that the user may enter the letter "A" or 0 to 50 for textbox1 and so on with other textboxes

    Just the letter "A" allowed along with the values ..
    As for values everything is ok but I couldn't enter the letter "A" ..

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    It sounds like "A25" would be an acceptable entry. (assuming the cell imposed limit was large enough)

    Would "A025" be acceptable?
    Would "25" be acceptable?

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    I'm sorry for confusing
    the entry would be either the letter "A" or a value between 0 and 50 ...(just two cases one for text possibility and the other case for a value between two sides "minumum and maximum"

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    Assuming that minimum < 25 < maximum:

    Would "A25" be acceptable?
    Would "A025" be acceptable?
    Would "25" be acceptable?
    Would "025" be acceptable?
    Last edited by mikerickson; 12-24-2015 at 05:31 PM.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    A25 not acceptable
    A025 not acceptable
    25 is ok
    025 not acceptable

    Look I am dealing with marks for subjects and each subject has a mimnum and maximum value
    At the same time , there would be some absent students so the user enter the letter "A" in this case
    Hope it is clear now

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    This version of the addition should do what you want. (it is assuming that you will be entering integers only.)
    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    Thanks again for this perfect version of the code
    my last fix (I'm dealing with decimals not just inegers as the marks would be sometimes 20.5 or 25.25 or 33.75 and so on)

    Also I need to display a message if the user entered any other letter except "A" ..as a kind of a lert
    Regards

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    This version of NumericBox_KeyPress will do what you want.
    I prefer just substituting an A entry to a warning msgbox. (User presses "B", "A" is entered in box). If you want that you can comment out that msgbox line.


    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    Thank you very very much for this fascinating solution
    Now it is perfect ...

    Just last little point (Sorry for disturbing you)
    I need to use an Arabic letter instead of "A" ..my letter is "غ" but when replacing "A" in your code with "غ" it appears in weird way in textboxes ..
    Any idea about that

  15. #15
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    Change this section of the code
    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    Great great
    thank you very much
    Can you provide me a tutorial of ChrW function as it seems very useful for me?
    Just a remark (I promise to be the last) ..Why I have a message box even if I entered "غ" ..it is supposed that it is the default allowed letter so I don't expect to get the alert message
    When I change the language input to type the letter "غ" I got error messsage at this line
    Please Login or Register  to view this content.

  17. #17
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Restrict entries in textboxes on userform

    I don't know what key results in that character, so I don't know how to test for it. The code is written to show the msgbox when other than "A" is entered. My style would be to remove that msgbox entirely.

    Its a smoother interface to correct a user's mistakes (hitting the wrong key) rather than nagging them about it. Since there is only one alphabetic entry allowed, if the user attempts any alphabetic entry, the routine automatically enters the correct text. No nagging is needed.

    Tutorials
    https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
    http://dailydoseofexcel.com/archives...scw-functions/
    Last edited by mikerickson; 12-25-2015 at 01:58 PM.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Restrict entries in textboxes on userform

    Thanks a lot for the advice ..
    You have done great effort in this thread ..thank you very much for your effort and time
    Regards

+ 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. Restrict textbox entries to numbers
    By domnisignis18 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-11-2013, 03:48 AM
  2. [SOLVED] Populate listbox columns with entries from textboxes on userform
    By AndyE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2012, 11:05 PM
  3. Restrict entries according to date in another cell
    By Canajun in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 12-10-2008, 12:47 AM
  4. [SOLVED] Textboxes - restrict double-click and selection.delete
    By korrin.anderson@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2006, 04:15 PM
  5. Restrict Data Entry to only 4 possible entries
    By ph8 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2006, 11:25 AM
  6. [SOLVED] RE: Restrict Data Entry to only 4 possible entries
    By Tom Ogilvy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2006, 11:25 AM
  7. RE: Restrict Data Entry to only 4 possible entries
    By Tom Ogilvy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2006, 11:15 AM
  8. [SOLVED] Excel2000: Data Validation to restrict entries
    By Arvi Laanemets in forum Excel General
    Replies: 1
    Last Post: 02-22-2005, 05:39 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