+ Reply to Thread
Results 1 to 18 of 18

Data validation format Letter number letter number etc.

  1. #1
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Cool Data validation format Letter number letter number etc.

    Hi,

    I had a quick look through some of the previous post and couldn't find a solution to my problem.

    I want to apply Data Validation to a cell, so that only the following combination of letters and numbers can be entered.

    Letter Letter Number Number Number Number Number Number Letter.
    e.g AB123456C.

    Any help would be greatly appreciated,
    Thanks,
    Dave
    Last edited by DaveM13; 07-13-2009 at 05:47 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    Would it be OK if the wrong cells were highlighted in, say a red colour?

    If so, this formula applied as a conditional format to your cell will achieve that type of result for cell A1:

    Please Login or Register  to view this content.
    You would need to set the highlight colour to whatever one you want.

    If a user then enters say ABC123456D, the cell will be highlighted in the selected colour.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  3. #3
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    Hi deadlyduck,

    Thanks for the reply.

    although conditional formatting is one way to go, i really need a data validation control to enforce the format (UK national insurance number)

    After looking through the forums a bit more, i found the following formula posted by donkeyote, which works to some extent, but not completly.

    =AND(AND(CODE(LEFT(B3,1))>=65,CODE(LEFT(B3,1))<=90),AND(CODE(MID(B3,2,1))>=65,CODE(MID(B3,2,1))<=90) ,AND(CODE(RIGHT(B3,1))>=65,CODE(RIGHT(B3,1))<=90),ISNUMBER(0+MID(B3,3,6)))

    Any ideas?

    Thanks,
    Dave

  4. #4
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    A slight tweak allows the formula to be used in data validation:

    Use the following formula in the Data validation | Custom setting:

    Please Login or Register  to view this content.
    IMPORTANT NOTE: The user must enter letters as lower case using this validation setting.
    Last edited by deadlyduck; 07-11-2009 at 09:54 AM.

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Data validation format Letter number letter number etc.

    Actually, I think this modification of DeadlyDucks' formula, used with Custom option for Data Validation will do the job:


    =AND(ISTEXT(LEFT(A1,2)),ISNUMBER(MID(A1,3,6)*1),ISTEXT(RIGHT(A1,1)))

    The NOT() function is removed from the formula.

  6. #6
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    Afraid my original formula won't do the job- the data a7123456c won't be caught as an error as Excel will read the 7 as text without a further check.

  7. #7
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    Hey Guys,

    Thanks for both of the suggestions, but neither seem to work, whether its me inputting it wrong or if its the formulas i do not know.

    Also, as a side not, the last letter in the national insurance number must only be on of the following letters - A B C D F or M.

    Any further help greatly appreciated.

    Dave

  8. #8
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    Perhaps using a helper column besides the cell where the data is entered will help eg if you enter this formula into the helper cell (say A3 or C3) beside where the data will be entered (B3) you could then apply a data validation test to check if the helper cell reads TRUE or FALSE, with appropriate feedback as required:

    =AND(OR(AND(CODE(LOWER(LEFT(B3,1)))>=97,CODE(LOWER(LEFT(B3,1)))<=122),AND(CODE(LEFT(B3,1))>=65,CODE(LEFT(B3,1))<=90)),OR(AND(CODE(LOWER(MID(B3,2,1)))>=97,CODE(LOWER(MID(B3,2,1)))<=122),AND(CODE(MID(B3,2,1))>=65,CODE(MID(B3,2,1))<=90)),OR(AND(CODE(LOWER(RIGHT(B3,1)))>=97,CODE(LOWER(RIGHT(B3,1)))<=122),AND(CODE(RIGHT(B3,1))>=65,CODE(RIGHT(B3,1))<=90)),ISNUMBER(0+MID(B3,3,6)))

    {The foregoing allows upper and lower case letters to be entered into B3}

    You'd then set the data validation to Custom | =AND((C3=TRUE),OR(RIGHT(B3,1)="A",RIGHT(B3,1)="B",RIGHT(B3,1)="C",RIGHT(B3,1)="D",RIGHT(B3,1)="F",RIGHT(B3,1)="M")). If a user misenters a character, this will be trapped.

    It also will prevent a user from entering anything other than A,B,C,D,F or M as the last character
    Last edited by deadlyduck; 07-11-2009 at 10:49 AM.

  9. #9
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    Deadly Duck,

    Brilliant idea, i never thought of using a check column.

    The formulas work perfectly except for one element. For example if i enter AB123456789878756C, it still thinks this is correct.

    Any Ideas?
    Thanks for all your help so far on this,
    Dave

    PS. In your last post there is a typo near the end of the formula (RI GHT) - space in the word right. The only reason i bring this to your attention is incase anyone looks at this thread in the future.

  10. #10
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    To ensure the length of the data is correct, change the Data validation setting to the following:

    Please Login or Register  to view this content.
    Thanks for spotting the typo

  11. #11
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    Thanks =)

    That works perfectly and covers all possible input error i could think of.

    Thanks for all your time on this.

    One more cheeky request, is there anyway i can enforce capital letters, or make the cell change lowercase to capitals automatically?

    Dave.

  12. #12
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    That's probably a VBA solution you're looking for.

    I'm not really competent in VBA but I'd say if you either search the forum/ create a new thread you'll find someone who'll have the answer for that.

  13. #13
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    OK, brilliant.

    Thanks again for your help,
    dave

  14. #14
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    Hi again,

    All was working perfectly, until I entered an incorrect format which was not trapped by the data validation.

    I did a few tests on it and the current validation also allows the following formats:

    JC123E46D
    JC1234E6D

    Any Ideas?
    Dave

  15. #15
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Data validation format Letter number letter number etc.

    Have you considered using three cells in which to enter the data and using a fourth cell to join them? By using three separate data entry cells you should be able to enforce the validation of the entries to your exact requirements.

    Data Validation, Custom Option:
    Data cell #1: =AND(ISTEXT(A1),LEN(A1)=2)
    Data cel #2: =AND(ISNUMBER(B1),LEN(B1)=6)
    Data cell #3: =AND(ISTEXT(C1),LEN(C1)=1)

    Join formula: =UPPER(A1)&B1&UPPER(C1)

    Another option: create a user form for the input and control the data with VBA.

  16. #16
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: Data validation format Letter number letter number etc.

    OK- it seems that Excel interprets the letter e when preceded and followed by a number as an exponent [could conceivably be useful to know :-) ]

    Change the 'big formula' above to the following (new bit in red) and it should cater for that situation:

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    07-11-2009
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Data validation format Letter number letter number etc.

    Quote Originally Posted by Palmetto View Post
    Another option: create a user form for the input and control the data with VBA.
    I could, but i have absolutly no knowledge of VBA, but thanks for the suggestion.

    Change the 'big formula' above to the following (new bit in red) and it should cater for that situation:
    Thanks, works perfectly now. I only wish i knew what it all meant.

    Dave

  18. #18
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Data validation format Letter number letter number etc.

    Appreciate this was resolved but just came across in a Search... and on the off chance you were still looking to do without helpers... and to help enforce Upper Case...

    Quote Originally Posted by DaveM13 View Post
    After looking through the forums a bit more, i found the following formula posted by donkeyote, which works to some extent, but not completly.

    =AND(AND(CODE(LEFT(B3,1))>=65,CODE(LEFT(B3,1))<=90),AND(CODE(MID(B3,2,1))>=65,CODE(MID(B3,2,1))<=90),AND(CODE(RIGHT(B3,1))>=65,CODE(RIGHT(B3,1))<=90),ISNUMBER(0+MID(B3,3,6)))
    presumably the above fails re:

    Quote Originally Posted by DaveM13
    Also, as a side not, the last letter in the national insurance number must only be on of the following letters - A B C D F or M.
    and also the issue of E within MID(B3,3,6) ?


    If so then this validation rule can be adapted accordingly... first create a named range of the permissable last letters, eg:

    Sheet1!Z1 contains string: A,B,C,D,F,M
    Named Range: =_lastletters
    RefersTo: =Sheet1!$Z$1
    (you don't need to use a Named Range per se but using a Named Range does permit you to store the string of interest on a sheet other than that on which the validation is being applied)


    Your B3 Validation then becomes (incorporating issue of E):

    Please Login or Register  to view this content.
    If you wish to make case insensitive then encase all initial string references within UPPER functions - that being said your earlier post would imply you specifically want to enforce Upper Case - this should be catered for via the Validation as Lower Case letters will not be accepted.
    Last edited by DonkeyOte; 07-16-2009 at 03:17 AM.

+ 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