+ Reply to Thread
Results 1 to 7 of 7

Conditional Formatting Based on Specific Number/Letter Combinations

  1. #1
    Registered User
    Join Date
    10-24-2017
    Location
    Leeds, UK
    MS-Off Ver
    2016
    Posts
    2

    Conditional Formatting Based on Specific Number/Letter Combinations

    Hi all,

    I've been looking around but I can't find an easy solution to this one based on some other answers in threads, so I'm putting this out there. I think this is me being rather stupid more than anything else, but we'll see!

    I'm creating a column in which the user has to enter a UK vehicle registration plate, of (for example) "MM45 TGR" - 2 letters, 2 numbers, a space and then 3 letters at the end. I want the cell to be highlighted if the entered text isn't of this format; just as a nudge to make people check what they've entered (not all plates fit that format but the vast majority do).

    I feel that the required formula is somewhere along the lines of:

    =NOT(AND(ISTEXT(LEFT(A1,1,2))),ISNUMBER(LEFT(A1,3,4)*1),ISTEXT(RIGHT(A1,1,2,3)))

    but I know this not to be correct as a) it's a bodge from another thread that I've tried to adapt without quite fully understanding and b) Excel tells me so.

    All help appreciated!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Conditional Formatting Based on Specific Number/Letter Combinations

    Just going out at the moment so haven't got time to test it all out but the way I'd do it with some OR and AND conditions which test the code values of each position. i.e. letters A-Z must between codes 65-90 inclusive, a-z between 97-122 inclusive and and 1-9 between 49-57.

    One way to eliminate a space if one occurs is to first use SUBSTITUTE(text," ","").

    I'd be inclined to use a helper column to work it all out and then use the result of the helper column in the CF.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Conditional Formatting Based on Specific Number/Letter Combinations

    welcome to the forum. this could be pretty lengthy. i'll explain parts of it and it will be repetitive along the way. that is a certain code for each character in Excel. so the capital "A" is character 65. type A in cell A1 and use this formula in B1
    =CODE(A1)

    and Z is character 90. so in order to check if they are alphabets, i check them in UPPER case and see if they fall between 65 and 90. this checks for first letter.
    =AND(CODE(UPPER(LEFT(A1,1)))>=65,CODE(UPPER(LEFT(A1,1)))<=90)

    for first two letters (repeat and changed the red portion:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    to check for number, ensure you convert it to a number by two negations before using ISNUMER:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    check for space:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    check for last 3 letters:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    addition:
    lastly, add a NOT to your conditional formatting.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by benishiryo; 10-24-2017 at 09:53 PM.

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  4. #4
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: Conditional Formatting Based on Specific Number/Letter Combinations

    Try

    in conditional formatting.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  5. #5
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Conditional Formatting Based on Specific Number/Letter Combinations

    just to also explain to OP shukla's methods to see if it meets your needs, he is ascertaining 4 parts:
    1. the first 2 characters are NOT numbers
    ISERROR(MATCH(TRUE,ISNUMBER(--MID(LEFT(A1,2),ROW(INDIRECT("1:"&LEN(LEFT(A1,2)))),1)),0))

    2. the 3rd and 4th characters ARE numbers
    ISNUMBER(MID(A1,3,2)+0)

    3. there is a space in the 5th character
    NOT(ISERROR(SEARCH(" ",A1)=5))

    4. the last 3 characters are NOT numbers
    ISERROR(MATCH(TRUE,ISNUMBER(--MID(RIGHT(A1,3),ROW(INDIRECT("1:"&LEN(RIGHT(A1,3)))),1)),0))

    you have to decide if the checking for alphabets meets your needs because he is only checking if they are NOT numbers. That means it will pass even if they are symbols, spaces, small casing. if it doesn't matter, then it's a much easier approach.
    it could be:
    ~ 45 abc

  6. #6
    Registered User
    Join Date
    10-24-2017
    Location
    Leeds, UK
    MS-Off Ver
    2016
    Posts
    2

    Re: Conditional Formatting Based on Specific Number/Letter Combinations

    Brilliant, thanks very much chaps! These solutions all seem to have worked upon trial, so chapeau to you all!

    Luckily just checking for it not being a number is good enough - as it is just nudging the poor sod doing data entry to check again, which hopefully a highlight will do!

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Conditional Formatting Based on Specific Number/Letter Combinations

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Conditional formatting for specific phone number format
    By nwpassage in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-10-2015, 12:30 PM
  2. [SOLVED] Conditional Formatting specific number of columns
    By JZ119 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2014, 09:51 PM
  3. [SOLVED] Conditional formatting if a number starts with specific digits
    By vshukla in forum Excel General
    Replies: 7
    Last Post: 01-23-2014, 12:43 PM
  4. [SOLVED] Conditional Formatting to change text in cell if other cell contains specific letter
    By RichTea88 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2014, 06:47 AM
  5. [SOLVED] Conditional formatting, highlight multiple of a specific number
    By Mihail-Cosmin in forum Excel General
    Replies: 11
    Last Post: 03-21-2012, 12:16 PM
  6. Creating a Marco to Replace a Specific Number with a Specific Letter in a Column
    By goldbeje in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-27-2011, 11:26 AM
  7. conditional formatting and letter/number grades
    By markjohnston in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 03-08-2010, 09:38 PM

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