+ Reply to Thread
Results 1 to 13 of 13

Change color of cell depending of value.

  1. #1
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Change color of cell depending of value.

    Hi!

    I'd like to change color on a cell depending on the value typed in the cell. The value in the cell is also depending on a previous value typed in another cell.

    https://postimg.org/image/8nmzoc6ct/

    Lets say this,
    In column A I can choose three different alt.(K,L,M), those three values have different requirenments,

    K = 1-3
    L= 4-6
    M= 7-10

    If I type L in column A the requirenment for the corresponding column B.
    Lets say that I type in 10 in column B, the requirenment is not met (Should be 4-6). Now I want this cell to be red.


    I've tried using VLOOKUP and a helping chart like this,
    K 1 3
    L 4 6
    M 7 10

    I have around 100 lines of values and with this method I have to put in all of these manually.
    Even the conditional formatting is not working.

    https://postimg.org/image/eq9fxe41f/
    From the pict above you can see that I have one line for every data input. I would like to have max 3 lines that fullfilles every value input in a column.

    Thanks for the help.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Change color of cell depending of value.

    (How to) Upload a Workbook directly to the Forum
    (please do not post pictures or links to worksheets)
    • Click Advanced next to Quick Post button at the bottom right of the editor box.
    • Scroll down until you see "Manage Attachments",
    • Click the "Choose" button at the upper left (upload from your computer).
    • Select your file, click "open", click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Close the Attachment Manager window.
    • Click "Submit Reply"
    Note: Please do not attach password protected workbooks/worksheets
    Ensure to disable any Workbook Open/Autorun macros before attaching!
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Re: Change color of cell depending of value.

    Sorry about that!
    Attached Files Attached Files

  4. #4
    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
    53,048

    Re: Change color of cell depending of value.

    Try this in a Conditional Formatting Rule (use Formula)...
    =OR(AND($A2=$F$2,OR($B2<$G$2,$B2>$H$2)),AND($A2=$F$3,OR($B2<$G$3,$B2>$H$3)),AND($A2=$F$4,OR($B2<$G$4,$B2>$H$4)))
    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

  5. #5
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Re: Change color of cell depending of value.

    Look in sheet3 (Column A and B) , this is not a nice solution, but when data is added you get the requirement for that value.
    So for every line I get the corresponding requirement (A,B)

    The formula you gave me works fine FDibbins but if I have more lines, like now, how should I do it?

    Note that the data sheet is not included here.

    Thanks!
    Attached Files Attached Files

  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
    53,048

    Re: Change color of cell depending of value.

    This again is a perfect example of when a member makes a dummy file that really does not match the real life data.

    What is supposed to match what here?
    Give me some sample answers so I can see what you want

  7. #7
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Re: Change color of cell depending of value.

    may be so, but in my first post I said that I wanted the color coding for aprrox 100 lines of data. Then again I understand that it created some confusion, sorry about that.

    I attached the file I'm working with now. There are some columns with other data that is deleted. I just kept the data needed in the correct columns.

    Thank you for your help.
    Attached Files Attached Files

  8. #8
    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
    53,048

    Re: Change color of cell depending of value.

    What I meant was that in your 1st example, you had a clear set of criteria - 3 sets of codes, each with a lower and an upper limit. That made ity easy to see what you were testing against. the actual length of your data set, is not really an issue, you would just need to adjust the "applies to" range accordingly.

    However, with the 2nd and 3rd files, Im having a hard time trying to make out your testing criteria - is that what you have (in a single cell) in E1 on sheet1?

  9. #9
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Re: Change color of cell depending of value.

    If you can see my latest file attached. The first thing I want to do is to choose the temperature (95,RT,-40) in column A. When choosing the temp I change the requirement for column E.

    For example A3 is -40. The value added in E3 is 0.200. This means that the value is within the critera.

    On the other hand we have A15 (95), the value added in E15 is 0.504, this value does not meet the criteria and should be colored.

    What you can see in sheet3 is just an attmept to solve the problem.
    If you have any other suggestions I'm all for it.

    I'm not even sure if I answered your question right now.

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Change color of cell depending of value.

    =$E3>=INDEX(LBound,MATCH($A3,Temp,0))*($E3<=INDEX(UBound,MATCH($A3,Temp,0)))=FALSE
    -----------------------------------------
    named Ranges:
    Temp =Sheet3!$G$1:$G$3
    UBound =Sheet3!$I$1:$I$3
    LBound =Sheet3!$H$1:$H$3
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Re: Change color of cell depending of value.

    Thank you! This worked.

  12. #12
    Registered User
    Join Date
    12-26-2016
    Location
    Shanghai
    MS-Off Ver
    2013
    Posts
    16

    Re: Change color of cell depending of value.

    I was thinking of another solution.
    If I only use conditional formatting and add this "code":

    If E3 is equal to -40 and have values under 0.14 OR over 1.16 change cell color.
    If E3 is equal to RT and have values under 0.14 OR over 1.25 change cell color.
    If E3 is equal to 95 and have values under 0.56 OR over 1.44 change cell color.

    Is it possible to do it this way? and how would I do it?

    I tried this with no sucess.

    =AND($E3="-40";OR(N3<0.14;N3>1.16))
    =AND($E3="RT";OR(N3<0.14;N3>1.25))
    =AND($E3="95";OR(N3<0.0.56;N3>1.44))

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Change color of cell depending of value.

    In the originally posted workbook, the temps -40, RT and 9,5 are in column A not column E and there is no data in column N. Instead the Force... is in column E

    The criteria table is on sheet3 not sheet1 so the criteria cells cannot be referenced directly in the Conditional Format formula, therefore I had to use the named ranges given.

    Notice in the formula, =AND($E3="-40";OR(N3<0.14;N3>1.16)) that you have put the -40 in quotes making it a character/text string not a numeric value. In the workbook , -40 and 95 are numbers, not text; so, those two formulas will always result in False.

    Your

    OR(N3<0.14;N3>1.16)

    is testing whether N3 is outside of the acceptance range . If the test is TRUE then you want to fill the cell red. You use the AND function instead of the OR: AND(N3>0.14;N3<1.16) you must reverse the direction of the inequality tests and test for FALSE. The AND alternative FORM is what I used.

    =$E3>=INDEX(LBound,MATCH($A3,Temp,0))*($E3<=INDEX(UBound,MATCH($A3,Temp,0)))=FALSE.

    Try:
    =AND($E3=-40;OR(N3<0.14;N3>1.16))=TRUE (for red cell)

+ 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. [SOLVED] Change cell color depending on cell color, error in code
    By mushedpotatos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2014, 04:20 AM
  2. Change shape fill color depending on cell value
    By xe-dingo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2013, 03:46 AM
  3. Change cell fill when changed different color depending on the day
    By rev0jace in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2012, 11:06 AM
  4. Change tab color depending on cell value
    By rirons04 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-01-2011, 02:34 PM
  5. Replies: 3
    Last Post: 07-08-2010, 06:48 PM
  6. Change Rows Color Depending on Cell Value in that row.
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-22-2009, 06:14 PM
  7. Change color depending on cell value
    By Gary Paris in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2005, 08:08 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