Consulting

Results 1 to 11 of 11

Thread: Solved: AlphaNumber Formula

  1. #1

    Solved: AlphaNumber Formula

    I want a formula to check the TRUE or FALSE for the following structure:

    The text structure is as given : AAVCF5678G

    The Length is 10
    Left 5 are characters from A to Z
    Next four are Numbers from 0 to 9
    Last one is Character (A to Z)

    How do I design a formula so that the result will come TRUE if input is correct and FALSE if input does not match the said criteria?

    Regards
    Sujit Talukder

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    =AND(ISTEXT(LEFT(A2,5)),ISNUMBER(--MID(A2,6,4)),ISTEXT(RIGHT(A2,1)),NOT(ISNUMBER(FIND({".",",",":",";","\","/","!"},A2))))

    you can add other not-allowed characters.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks xld. But this give result = TRUE even if in the Text entered in cell A2 as "AAVCF5 ". I wnat result to TRUE if full length of the text is entered. that is to say, when full AAVCF5678G is correctly entered then result should come TRUE else FALSE.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just add a length test

    =AND(LEN(A2)=10,ISTEXT(LEFT(A2,5)),ISNUMBER(--MID(A2,6,4)),ISTEXT(RIGHT(A2,1)),NOT(ISNUMBER(FIND({".",",",":",";","\","/","!"},A2))))
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Here we go again, another of NASA's launch codes. I'm trying to break this down and getting confused..... I'm assuming that;

    To test for correct length of the string is the LEN(A2)=10, and
    To test for first 5 characters to be text is ISTEXT(LEFT(A2,5)), and
    To test for numerals starting at position 6 is ISNUMBER(--MID(A2,5,4)), and
    To test for last character in string is ISTEXT(RIGHT(A2,1), and
    To test for non acceptable characters is NOT(ISNUMBER(Find([".",",",:",";","\","/"!"}, and
    If any of these test are false, return A2.

    Can I therefore also assume a single AND can encompass more than two tests? Is there a limit to the number of tests one can imply?

    Next question relates to the non acceptable characters. Bob used NOT(ISNUMBER, yet the characters are not Alphabetical either. Are they therefore regarded as TEXT?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    To accept to A-Z and reject 1,2,3,#,$,a,b,etc (and to check for length >9)

    =AND(65<=MIN(CODE(MID(A1&"xxxxxxxxxx",{1,2,3,4,5,10},1))), MAX(CODE(MID(A1&"xxxxxxxxxx",{1,2,3,4,5,10},1)))<=90)

    Edit:

    Expanding on that, I think this will do what you ask
    =AND({65,65,65,65,65, 48,48,48,48, 65}<=CODE(MID(A1,{1,2,3,4,5,6,7,8,9,10},1)), _
    CODE(MID(A1,{1,2,3,4,5,6,7,8,9,10},1))<={90,90,90,90,90, 57,57,57,57, 90}, _
    LEN(A1)=10)
    Last edited by mikerickson; 06-15-2012 at 10:12 PM.

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    I've ordered a doctor for you Mike.... . You are going to have to break this one down into something simple for me.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Aussiebear
    To test for correct length of the string is the LEN(A2)=10, and
    To test for first 5 characters to be text is ISTEXT(LEFT(A2,5)), and
    To test for numerals starting at position 6 is ISNUMBER(--MID(A2,5,4)), and
    To test for last character in string is ISTEXT(RIGHT(A2,1), and
    To test for non acceptable characters is NOT(ISNUMBER(Find([".",",",:",";","\","/"!"}, and
    If any of these test are false, return A2.
    Almost., it returns TRUE or FALSE, not A2

    Quote Originally Posted by Aussiebear
    Can I therefore also assume a single AND can encompass more than two tests? Is there a limit to the number of tests one can imply?
    Absolutely it can. I have no idea what the limits might be, never been anywhere near that.

    Quote Originally Posted by Aussiebear
    Next question relates to the non acceptable characters. Bob used NOT(ISNUMBER, yet the characters are not Alphabetical either. Are they therefore regarded as TEXT?
    They are not numeric, but FIND returns the numeric position of the character, or returns #VALUE!. so we are testing that for numeric not the values themselves.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Quote Originally Posted by Aussiebear
    I've ordered a doctor for you Mike.... . You are going to have to break this one down into something simple for me.
    MID(A1,{1,2,3,4,5,6,7,8,9,10},1)
    is an array of each of character in A1
    CODE(MID(A1,{1,2,3,4,5,6,7,8,9,10},1)) is the ascii values for those characters

    {65,65,65,65,65, 48,48,48,48, 65}<=CODE(MID(A1,{1,2,3,4,5,6,7,8,9,10},1))

    Is an array of True/False values if the characters are above their limits.

    It would be easier to see in this formulation:

    {"A","A","A","A","A","0","0","0","0","A"}<=MID(A1,{1,2,3,4,5,6,7,8,9,10} ,1)
    returns an array of true/false values

    AND({"A","A","A","A","A","0","0","0","0","A"}<=MID(A1,{1,2,3,4,5,6,7,8,9,10 },1)) evaluates to TRUE only when

    "A" <= first character , and
    "A" <= second character , and
    ...
    "0" <= fifth character , and
    "0" <= sixth character , and
    ...
    "A" <= last character

    Combining a second condtion
    =AND(_
    ({"A","A","A","A","A","0","0","0","0","A"}<=MID(A1,{1,2,3,4,5,6,7,8,9,10},1 )), _
    (MID(A1,{1,2,3,4,5,6,7,8,9,10},1)<={"Z","Z","Z","Z","Z","9","9","9","9","Z" }))

    is true only if
    "A" <= first character AND first character <= "Z" , and
    "A" <= second character AND second character <= "Z" , and
    ...
    "0" <= fifth character AND fifth character <= "Z" , and
    "0" <= sixth character AND sixth character <= "Z" , and
    ...
    "A" <= last character AND last character <= "Z"

    That is if each character is of the correct type, the formula returns TRUE, False otherwise.

    NOTE. The approach in this post (without CODE) is case insensitive since "r"<"Z"
    Using the CODE formulation above is case sensitive.

    (Adding the "xxxxxxxxxx" prevents a #VALUE error when A1 is shorter than 10. Any string of 10 illegal characters would work.)

  10. #10
    thanks to all the reply and solution.

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    @Bob, thank you for your advice, and

    @Mike, Your explanation will take a few re reads to comprehend. Maybe when I'm more alert. But thanks anyway.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •