+ Reply to Thread
Results 1 to 16 of 16

Highlighting one or two numbers in a column based on a value in another column

  1. #1
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Highlighting one or two numbers in a column based on a value in another column

    Hello, I am a novice Excel user (but learning!). I am new here but have found some great information and have almost solved my problem on my own.

    I want to have Excel highlight one or two numbers/cells in one column based on the value in another cell. I am attempting to do this using Conditional Formatting.

    For example, if X1 is BETWEEN A2 and A3, I want to highlight A2 AND A3. I have used various AND and IF functions to achieve this goal.
    Also, if X1 is EQUAL to A2, I want A2 to be highlighted. This is easy to do with a simple formula.

    But my problem is this: if X1 is equal to A2, I want ONLY A2 highlighted. If X1 is between A2 and A3, I want BOTH A2 and A3 highlighted. I cannot figure out how to achieve both. For example, when X1 = A3, A2 AND A3 are being highlighted, instead of just A3. I would prefer to do this without a macro, if possible. Can this be done?

    Example formulas I have tried which easily achieve the highlighting of two cells when the value is between them:

    Condition 1=IF(AND($I$35>I8,$I$35<I7),1," ")+IF($I$35<>I7,1," ")
    Condition 2=IF(AND($I$35<I6,$I$35>I8),1," ")+IF($I$35<>I7,1," ")

    It appears that the +IF, etc. functions are not doing anything.

    This is more complicated by the fact that the value of, in the above example, I35 is based on a value from another sheet (I used a function to transfer a value from one sheet to I35 in the other sheet). As data are entered on Sheet1, the value in I35 in Sheet2 changes.

    Hopefully this all makes sense. Thank you for any help.
    Last edited by thehim; 05-18-2013 at 04:34 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

    I would think this one CF formula is all you need:

    =OR(AND($I6<=$I$35,$I7>=$I$35),AND($I7<=$I$35,$I8>=$I$35))


    CF formulas don't need IF statements, by design they should resolve to simple TRUE/FALSE results.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    Thank you for your help! That formula looks promising but it did not work. Perhaps I need to provide more information, or I may be doing something wrong.

    I want the formula to act on the values in the cells of the column I, I7 through I32. The other value is I35. In my example I used "$I$35" to keep I35 absolute, so that I could select the entire I column (7 through 32), enter conditional formatting, and enter a single function for all cells (because Excel would automatically change the other cell designations). I tried your formula with and without the "$" symbols (except for in reference to I35), but nothing is being highlighted.

    To make it more clear, column I looks like this (the first column here is just to designate cell numbers):

    I
    7 4.92
    8 4.08
    9 3.78
    10 3.58
    11 3.36
    12 3.27
    13 3.18
    14 3.09
    15 3.00
    16 2.91
    17 2.83
    18 2.78
    19 2.73
    20 2.70
    21 2.67
    22 2.63
    23 2.58
    24 2.55
    25 2.52
    26 2.50
    27 2.46
    28 2.42
    29 2.39
    30 2.35
    31 2.31
    32 2.27

    Some examples of what I want to happen: if the value in I35 is 3.36, then cell I11 (containing 3.36) should highlight, and only this one should highlight. If the value in I35 is, say, 2.40, then I want I29 as well as I28 to highlight. I can only get it to highlight two cells, even when I35 equals one of the values above. Does that make sense?

    Also, I tried revisions of the formula you gave.

    If I use

    =OR(AND(I6>=$I$35,I7<=$I$35),AND($I7>=$I$35,$I8<=$I$35),I7=$I$35)

    It will highlight two numbers even when I35 is equal to a value in one of the other cells. In other words, if I35 is 3.36, it highlights 3.36 AND 3.58.

    If I use

    =OR(AND(I6>=$I$35,I7<=$I$35),I7=$I$35)

    It will highlight only one number, regardless of the value in I35. For example, when I35 is 3.55, it correctly highlights 3.36, but does NOT highlight 3.58.

    This has me stumped. I figured there HAD to be a way to do what I want, but I cannot seem to get Excel to do BOTH things. It either always highlights one, or always highlights two.
    Last edited by thehim; 05-18-2013 at 06:05 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

    Ok, first, one normally expects an ordered table like that to ASCEND, not DESCEND, so the operators are backwards.

    Second, you will need two CF formulas if you only want one cell to light up when it's an exact match, but two to light up if it's an inbetweener.

    CF1: =$I7=$I$35 (you must set this rule to "STOP IF TRUE")

    CF2: =OR(AND($I6>$I$35,$I7<$I$35),AND($I7>$I$35,$I8<$I$35))

    http://screencast.com/t/tff0Cny0N

  5. #5
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    Thank you! The "Stop if true" command is exactly what I need, but I am using Excel 2003 (this is a work project and I am off on my weekend at the moment), and the conditional formatting dialog box looks completely different, and I do not remember seeing the "stop if true" command. I will try to figure that one out.

    I should have noted the order of the numbers. My tables are based on statistical data from another source, and I used the same order as the original.

    I will be interested to try this when I return to work on Tuesday. I just need to figure out how to set up the "stop if true" command, assuming it was in Excel 2003 (I do not have Office on my home machine or I would test this right now).

    Thanks again!

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Highlighting one or two numbers in a column based on a value in another column

    I dont believe 2003 has the "stop" option
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

    In Excel 2003 you can put up to 3 CF rules on a cell, in the order of importance. If any rule resolves to TRUE, it stops by design. You don't have a choice.
    Last edited by JBeaucaire; 05-20-2013 at 04:00 AM.

  8. #8
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    That is good to know! Thank you!

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

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

  10. #10
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    I greatly appreciate the feedback! For some reason this Excel sheet is still not doing what I want it to do. In the case of an exact match, it continues to highlight the cell above the match along with the match. When I select the entire column and enter the conditional formatting formula $I7=$I$35, it does not automatically apply it to the other cells (i.e., every cell has that formula, instead of changing to I8=, I9=, etc.). Even removing the "$" before the I7 does not do it. I tried manually entering the formula in each cell to apply to that cell, but that did not fix the problem either. I think the reason it is not working is because the formula only applies to one cell. Is there a way to make a formula that states "if ANY cell in that column is equal to I35, stop"? Can I do an OR formula with more than two possibilities? I have 26 rows in the column. Thanks again in advance for taking the time to help me with this problem. I greatly appreciate it. Just my working on it has granted major kudos at work for me

  11. #11
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    I just discovered part of the problem. The value in I35 is based on the value in another sheet. I used a formula to achieve this; i.e., =Sheet1!L19. Thus, when I use the =I35 function, nothing happens. If I manually enter a number in, say, I36, then it highlights it properly if I36 matches a number in my column. So here is the real problem, since I35 is based on the value of another cell in another sheet, and I can't use conditional formatting in reference to other sheets, is there another way to do this? I35 has to come from another cell in another sheet. If I move my table from sheet2 to sheet1, I run into a different problem. The cell value I want to match to the cells in the column is based on a formula, and this appears to cause a problem.

    If I use conditonal formatting to reference a cell which has a value based on a formula and/or other cells, will it work? This does not appear to be the case. In other words, consider my formula I7=$I$35. In I35 is the formula =L18/11. Going further, in cell L18 is the formula =SUM(L7:L17). So in the formula I7=$I$35, is it referencing the value in I35, or the formula L18/11 and not recognizing that as a value? I hope this makes sense.

    If I knew how to write Visual Basic code I would consider using a macro, but I'm not even at a beginner level there. And considering I have 26 rows and seven columns, I would imagine the macro would be quite complex. Lastly, I like that conditional formatting updates when numbers are entered. I am creating this Excel sheet for a beginner to use, just to enter numbers in the appropriate boxes, and then Excel does the rest. I don't want the person to have to run a macro to highlight numbers.

    Thanks again for any help.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

    Post a usable workbook demonstrating all these problems/needs.

    Make sure there is just enough data to make it clear what is needed. Include BEFORE and AFTER sheets if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  13. #13
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    I probably should have uploaded something to begin with.

    The file is a sample file with none of the conditional formatting inserted. I deleted all irrelevant data. On the "client data" sheet, there are white boxes surrounded by yellow areas. These white boxes are where data are entered. The sums and means in the yellow areas (rows 18 and 19) are then automatically calculated. On the "percentages" sheet, Row 35, columns C through M, contain numbers calculated in the "client data" sheet. Rows 7 through 32 in columns C through M contain data which must remain as entered (based on data from an outside source). What I want is for the values in the C through M columns to be highlighted based on the values in row 35. If a value in column C exactly matches C35, then that value should be highlighted. If the value in C35 is between two values in column C, I want both highlighted. In other words, if C35 = 3.03, I want C15 (3.03) highlighted, and ONLY C15 (for that column). If C35 = 3.00, I want BOTH C15 (3.03) and C16 (2.97) highlighted. This applies to each column.

    Notice that when data are entered into the boxes in the "client data" sheet, the numbers in sheet "percentages," row 35 change, but these are the only numbers that change in the "percentages" column.

    Preferably, I would like the highlighted cells to be highlighted as such: exact match, single cell = pattern Bright Green, font face Bold, text color black; inbetween, two cells = pattern Green, font face bold, text color white.

    Hopefully this all makes sense.

    Finally, I am not averse to the idea of having both sheets on a single sheet, and I can re-format the "percentages" sheet if it needs to be moved. As long as the numbers are highlighted, that's all that matters!

    Thanks again!
    Attached Files Attached Files
    Last edited by thehim; 05-22-2013 at 07:54 PM. Reason: *all references to "percentages" sheet should refer to "percentiles" sheet. My mistake!

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

    I think you can fix this yourself with the solutions given already. The problem is the values in row35 look like one thing, but are another.

    The value C35 is showing as 3.77, but the value is actually 3.770391414

    If you correct that so it really can be evaluated as only a two-decimal value, the other CF formulas provided earlier can work, and you can amend the coloring as well to the scheme you've mentioned.

    So, the formula in C35 that "fixes" the value in C35 to only two decimals would be:

    C35: =ROUND('Client Data'!U25, 2)



    Keep this in mind in the future. Values displayed as the result of a formula that divides may need to be rounded before additional math is done to eliminate unwanted values past the decimals allowed.

  15. #15
    Registered User
    Join Date
    05-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Highlighting one or two numbers in a column based on a value in another column

    I do not have time today to implement all the formulas, but in my initial test of the ROUND addition, it worked! Thank you so much for your help. This appears to have been the key. Looking back it seems so simple, but as a novice user I had no way of knowing this was what I needed. Much appreciated!

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlighting one or two numbers in a column based on a value in another column

    Glad to hear. Don't beat yourself up over the rounding thing, it is not obvious until it bites you one time real hard, as it has done to all of us.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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