+ Reply to Thread
Results 1 to 8 of 8

Google Sheets: conditional formatting for cell containing letters and numbers

  1. #1
    Registered User
    Join Date
    05-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Google Sheets: conditional formatting for cell containing letters and numbers

    Good day experts,

    I would like to ask how to change the background color to red when a cell contains letters and numbers and the number is above 120 and change the color to green when the number is below 120.
    Attached Images Attached Images

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    The solution below is based on the values provided in post#1
    - this solution is only correct if those cells containing both letters & numerics are constructed [2 letters followed by space followed by numerics] (as in your sample data)

    CF formula
    =IF(ISNUMBER(A1),"Number only",IFERROR(IF(SEARCH(" ",A1)>0,IF(TRIM(SUBSTITUTE(A1,LEFT(A1,2),""))*1>120,"Red","Green")),"Text only"))="Green"

    =IF(ISNUMBER(A1),"Number only",IFERROR(IF(SEARCH(" ",A1)>0,IF(TRIM(SUBSTITUTE(A1,LEFT(A1,2),""))*1>120,"Red","Green")),"Text only"))="Red"

    The logic of the formula
    - is A1 a number? (we can ignore if A1 only contains a number)
    - if A1 is not a number, does it contain a space? (we can ignore if A1 does not contain a space because it contains only non-numerics or is empty)
    - if A1 is neither of the above it contains both
    - if A1 contains both, extract its numeric element and test against the 120 hurdle

    Why A1?
    When applying CF to a range of cells, the formula used is the one that would be correct for the top left cell in the range
    - CF was applied to (entire) columns A & B and so the formula used is the one applicable to cell A1
    - columns D & E in attached workbook contain formulas that mimic what is used in the 2 conditional formatting rules so that you can see how it works,
    - they are not part of the solution and can be deleted after testing

    Sample data
    - the attached workbook contains your values and returns the requested results

    CF rule58.jpg


    Does not work with live data?
    If this does not work with your some of your real data, please attach a workbook with typical data that covers every eventuality
    Remember to desensitize the data.
    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Attached Files Attached Files
    Last edited by kev_; 04-11-2018 at 01:38 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    05-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    Thanks kev_. Works perfectly! You're amazing!

  4. #4
    Registered User
    Join Date
    05-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    Hi kev_,

    Follow up question. In the formula that you have provided (which is working really great) how do you prevent cells that contains two letters and 0 from changing colors.

    Thank you.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    Hmmm...
    (Untested) Perhaps insert an extra condition here (this is only part of the formula)
    IF(TRIM(SUBSTITUTE(A1,LEFT(A1,2),""))*1>0, IF(TRIM(SUBSTITUTE(A1,LEFT(A1,2),""))*1>120,"Red","Green"))
    but that seems a bit messy for one exception (I will try to think of a more elegant solution )

    Are there any other "funny" values?
    If there are send me a workbook with typical values

    .

    how do you prevent cells that contains two letters and 0 from changing colors.
    Is there a space?
    Last edited by kev_; 04-12-2018 at 04:33 PM.

  6. #6
    Registered User
    Join Date
    05-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    Yes, there is still a space. I just want to prevent DF 0 and GH 0 from changing colors. Sorry for the additional problem.
    Attached Files Attached Files
    Last edited by jher001; 04-12-2018 at 04:50 PM.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    In that case we can wrap a simple additional condition around everything checking to see if the last 2 characters of the cell are space followed by zero

    =IF(RIGHT(A1,2)=" 0","Text and Zero",IF(ISNUMBER(A1),"Number only",IFERROR(IF(SEARCH(" ",A1)>0,IF(TRIM(SUBSTITUTE(A1,LEFT(A1,2),""))*1>120,"Red","Green")),"Text only")))="Green"


    Same for "Red"
    Attached Files Attached Files
    Last edited by kev_; 04-13-2018 at 05:56 AM.

  8. #8
    Registered User
    Join Date
    05-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Re: Google Sheets: conditional formatting for cell containing letters and numbers

    Thanks, kev_. Works perfect! You're the best!!!!

+ 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. Google Sheets - Tricky conditional formatting with two requirements
    By ilorenzo in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 6
    Last Post: 07-19-2017, 08:53 PM
  2. Conditional formatting for multiple work schedules [Google Sheets]
    By theclarkmeister in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 06-30-2017, 06:34 PM
  3. Help required in conditional formating Google Sheets
    By balu2021 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 5
    Last Post: 04-06-2017, 04:05 AM
  4. email row contents based on cell values (google sheets populated by google forms)
    By reedg in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 01-13-2016, 02:55 PM
  5. Replies: 13
    Last Post: 07-09-2014, 04:10 PM
  6. [SOLVED] Conditional Formatting using letters and numbers
    By Excel_Beginner_1 in forum Excel General
    Replies: 4
    Last Post: 07-12-2012, 05:19 PM
  7. [SOLVED] conditional formatting with letters and numbers
    By bta in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-31-2009, 07:42 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