+ Reply to Thread
Results 1 to 16 of 16

Data Validation - Restrict cell with multiple conditions

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Red face Data Validation - Restrict cell with multiple conditions

    Dear folks,

    Much appreciate your help with below case:

    Restrict cell A1 with 2 conditions:
    - A1 must be alphanumeric
    - Length must be < 19

    I try OR(AND(CODE(A1)>=65,CODE(A1)<=90),AND(CODE(A1)>=97,CODE(A1)<=122),AND(CODE(A1)>=48,CODE(A1)<=57)) with the first condition but it seems like it only checks the first character of the cell.

    Thank you very much.

  2. #2
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    2010
    Posts
    225

    Re: Data Validation - Restrict cell with multiple conditions

    First, you can use HOME/CONDITIONAL FORMATTING....cell containing value between 0 (zero) and Z
    Then, DATA/DATA VALIDATION - Text Length between 0 (zero) and 18

  3. #3
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: Data Validation - Restrict cell with multiple conditions

    Please Login or Register  to view this content.
    I no sure what you code doing.
    I assume you want restrict cell by entering if no full-filled this 2 condition.
    -If the problem is solved, please mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved".

    -Always upload a workbook before start your question
    To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

    +++ If my answer(s) helped you, please add me reputation by click on * +++

  4. #4
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    First, you can use HOME/CONDITIONAL FORMATTING....cell containing value between 0 (zero) and Z
    Then, DATA/DATA VALIDATION - Text Length between 0 (zero) and 18

    Thank you.
    Conditional formatting won't stop user from keying in the unexpected characters. How can we combine two IFs in Data Validation?
    Last edited by hitarov; 07-10-2013 at 06:28 AM.

  5. #5
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    =AND(ISNUMBER(A1),LEN(A1)<19)

    I no sure what you code doing.
    I assume you want restrict cell by entering if no full-filled this 2 condition.

    the formula
    =AND(ISNUMBER(A1),LEN(A1)<19)
    will check if the cell is numeric only, not applicable for this case when Alphanumeric is allowed (means whole numbers (0, 1, ...) & alphas (a, b, c, A, B, C, ...).
    Last edited by hitarov; 07-10-2013 at 06:28 AM.

  6. #6
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    the formula
    =AND(ISNUMBER(A1),LEN(A1)<19)
    will check if the cell is numeric only, not applicable for this case when Alphanumeric is allowed (means whole numbers (0, 1, ...) & alphas (a, b, c, A, B, C, ...).

  7. #7
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: Data Validation - Restrict cell with multiple conditions

    Okay.I see wrongly.That formula only work on number.

  8. #8
    Forum Contributor
    Join Date
    07-02-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    197

    Re: Data Validation - Restrict cell with multiple conditions

    Quote Originally Posted by x65140 View Post
    First, you can use HOME/CONDITIONAL FORMATTING....cell containing value between 0 (zero) and Z
    Then, DATA/DATA VALIDATION - Text Length between 0 (zero) and 18
    Use Data validation as x65140 suggested

    Allow: Text length
    Data: Less than
    Maximum: 19

  9. #9
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: Data Validation - Restrict cell with multiple conditions

    Please Login or Register  to view this content.
    How about this, it will not accept any number.

  10. #10
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    2010
    Posts
    225

    Re: Data Validation - Restrict cell with multiple conditions

    What about trying this.......Data Validation

    =OR((AND(A1>=0,A1<=999999999999999999,LEN(A1<19))),AND(A1>="a",A1<="ZZZZZZZZZZZZZZZZZZ",LEN(A1)<19))

    It is AlphaNumeric....and will NOT let the FIRST byte be a special character...but still allows other bytes to be special....
    (will NOT allow '@ ' but will allow 'asw@ '
    does that help????

  11. #11
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    Quote Originally Posted by wenqq3 View Post
    Please Login or Register  to view this content.
    How about this, it will not accept any number.
    What I need is both alphabets & numbers should be allowed to key in.
    Thanks for trying.

  12. #12
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    Quote Originally Posted by x65140 View Post
    What about trying this.......Data Validation

    =OR((AND(A1>=0,A1<=999999999999999999,LEN(A1<19))),AND(A1>="a",A1<="ZZZZZZZZZZZZZZZZZZ",LEN(A1)<19))

    It is AlphaNumeric....and will NOT let the FIRST byte be a special character...but still allows other bytes to be special....
    (will NOT allow '@ ' but will allow 'asw@ '

    does that help????
    It should prevent user from keying in other characters but alphabets & numbers.
    Thanks for trying.

  13. #13
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    Quote Originally Posted by Rambo4711 View Post
    Use Data validation as x65140 suggested

    Allow: Text length
    Data: Less than
    Maximum: 19
    As I said, the conditional formatting won't prevent characters other than Alphabet & numbers.

  14. #14
    Forum Guru Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Data Validation - Restrict cell with multiple conditions

    If you want to allow only the letters A - Z, a - z and the digits 0-9...

    Create this defined named expression.

    Goto the Formulas tab>Define Name
    Name: String
    Refers to: ="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    OK

    Then, use this formula for the data validation:

    =AND(FIND(UPPER(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),String),LEN(A1)<19)

    When setting up the validation uncheck: Ignore blank

    If you test that formula in a worksheet cell it must be array entered.

    array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  15. #15
    Registered User
    Join Date
    07-10-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Data Validation - Restrict cell with multiple conditions

    Quote Originally Posted by Tony Valko View Post
    If you want to allow only the letters A - Z, a - z and the digits 0-9...

    Create this defined named expression.

    Goto the Formulas tab>Define Name
    Name: String
    Refers to: ="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    OK

    Then, use this formula for the data validation:

    =AND(FIND(UPPER(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),String),LEN(A1)<19)

    When setting up the validation uncheck: Ignore blank

    If you test that formula in a worksheet cell it must be array entered.

    array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Thanks a lot, I tried and it worked with similar formula:
    Please Login or Register  to view this content.

  16. #16
    Forum Guru Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Data Validation - Restrict cell with multiple conditions

    Good deal. Thanks for the feedback!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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