+ Reply to Thread
Results 1 to 20 of 20

Complex Conditional Formatting

  1. #1
    Registered User
    Join Date
    10-31-2007
    Posts
    11

    Complex Conditional Formatting

    I have colour code combinations which relate to numbers e.g.

    0.5 = Red, Red
    0.9 = Yellow, Black
    1.7 = Brown, Black
    2.25 = Orange, Black
    3.5 = Green, Black
    4.5 = Grey, Grey
    6 = Red, Black
    etc.....

    There are approx 50 numbers each with a unique two colour combination from 10 colours available.

    Assume that in cell A1 of the Excel spreadsheet I want to type in any one of the 50 different numbers. I need this then to conditionally format cell B1 pattern to the first colour, and cell C1 to the second colour. i.e.

    Cell A1 = 0.9
    Cell B1 to have Yellow background (no text in cell required)
    Cell C1 to have Black background (no text in cell required)

    In reality this will be repeated in rows 2, 3, 4, 5, etc. with different numbers.

    The simple solution would be conditional formatting, however this only allows a maximum of 3 conditions as opposed to 50.

    I also tried using vlookup to a table of the combinations in a separate sheet. This would return colour names ok but wouldn't copy formats. If there is a way of getting vlookup to return formats as well as cell contents, that would be great.

    I don't mind having to run a macro to format the cells (my attempts at this have failed), but use of a function in the cell which could do the same task automatically would be even better.

    Any ideas/solutions would be greatly appreciated!
    Last edited by satchmo; 10-31-2007 at 01:26 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    What hapens if the value is not in the list, e.g., 0.6?

    Suggest you make a 3-column named range: value, colorindex 1, colorindex2 (red = 3, black =1, yellow = 6, ...). The VBA to implement the formatting would be simple.
    Last edited by shg; 10-31-2007 at 01:36 PM.

  3. #3
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    I should be able sort the side of it in the case the value is not in the list however this is not too important as the people using the spreadsheet quite clued up. I can always set the number selection to come from a drop down list.

  4. #4
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    I don't understand what you mean about a 3 column named range. How would I go about doing this and what would the necessary VBA code be? I struggle beyond basic loops and if's etc in VBA.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Complex Conditional Formatting

    I attached a file that I does what you asked for (I think).

    The file DOES contain VBA code....and instructions....and documentation.

    Is that something you can work with?
    Attached Files Attached Files
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  6. #6
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    I just attempted to expand your solution for further "number = colour combination"'s by adding:

    Cell A10= 7.5
    Cell B10= Yellow_Color
    Cell C10= Gray_Color
    Cell J20= =Sheet1!$A$3:$C$10 (modified from =Sheet1!$A$3:$C$9)

    By entering 7.5 in one of the SchemeChoice cells I thought this would return a Yellow/Grey combination but it returned a blank. I looked at the code and to be honest it is totally beyond my level of understanding. When I attempt to modify a cell range in any of the cells J16 to J25 I don't get what I expect and if I manually change it back to what it was instead of using "undo" it doesn't return to what it was originally.

    I am extremely grateful for what you have provided and amazingly impressed by how you have done it. Unfortunately I do not understand the workings of it in order to expand it to the 10 colours and 50 number/colour combinations. At least you have opened my eyes to what is possible in Excel! I see there are no macros involved and the code does not seem to have any cell references which confuses me as to how you did this. Are there further hidden functions or code you have created in this?

    I really appreciate the time you have spent on this!

  7. #7
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    Envisiging that this is something that I would want to have as a secondary worksheet in the same file as the spreadsheet in question I've tried modifying cell references so that the scheme choice table is effectively where I need it in my current spreadsheet but this doesn't seem to work either. What am I missing? ... Something fundamental obviously!

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Complex Conditional Formatting

    Hi, Satchmo

    Here's what you're missing when you try to modify the file I posted:
    The model uses Range Names. A Range Name is a nickname for a range of cells. Range Names can be used in formulas and programming to make the formulas or code easier to read.

    For instance, if Sheet25, Cell AB102 contains the effective tax rate for your company, you can name that cell Eff_Tx_Rate. Then a formula would look like this: =Eff_Tx_Rate instead of =Sheet25!$AB$102........and you'd know what it referred to!.

    The list in cells I16:J25 is only there to show you the Range Names I used and which cells they refer to.

    To easily select any Named Range:
    Press the [F5] key........a shortcut for <edit><go to>
    ...Choose the Range Name you're interested in from the list.
    ...Click [OK]....The cells referenced by that Range Name will be selected.

    Here's an example for your file:
    Press the [F5] key........Select: Red_Color....Click [OK]
    Cell F3 will be selected.
    Now look in the Name Box (above the Col_A header)
    ....it indicates the Range Name: Red_Color.
    If you move to F4, the Name Box indicates: Black_Color.
    Those cells are NAMED.

    To view, edit, or create Range Names:
    From the Excel Main Menu: <Insert><Name><Define>
    The top box is where you'd type a new name to be created.
    The middle box is a list of existing Range Names
    The bottom box shows the cells that are referenced by the selected Range Name.

    If you choose LU_ColorSchemes,
    you'll see that it refers to: =Sheet1!$A$3:$C$9

    To change that reference to include Row_10,
    just edit the Refers To box to: =Sheet1!$A$3:$C$10
    Then Click [OK] if you're done....or Click [Add] to continue.

    Does that help?
    Post back if you have more questions.

  9. #9
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    Thanks again for your help. I have added the other colors and LU_ColorSchemes and everything worked correctly. I have now placed the actual worksheet in the workbook and attempted to make the SchemeChoice range be in sheet "Option 2". I couldn't get this to work and am stuck again. The LU_Val needs to be entered in cell range AZ19:AZ34 being the required SchemeChoice range which I have redefined to point at these cells. The colors to be returned need to appear in the preceeding two columns. I've attached the file for understanding of the problem.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    I also do not understand the requirement for the RGB mix?

  11. #11
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Complex Conditional Formatting

    Posting your actual file helped quite a bit.

    I reposted it as version 1a with the following changes
    Please Login or Register  to view this content.
    Let me know if that helps.

  12. #12
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    As far as I can see the v1a attachment is exactly the same as the original attachment?

  13. #13
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Complex Conditional Formatting

    Quote Originally Posted by satchmo
    As far as I can see the v1a attachment is exactly the same as the original attachment?
    You should be able to enter values in cells AZ19:AZ34 and see the colors of the cells to the right of them change.

    I'll attach it to this message, just in case.

    Does that help?
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    Still doesn't seem to be working. Don't know why?

  15. #15
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    p.s. It is the cells to the left which need to be the colors. NO colours are resulting though? I still don't believe how much you know about this stuff. Do you work for Microsoft?

  16. #16
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Complex Conditional Formatting

    I attached version 1b to this message.

    When you change the value under the torque label in AZ17, the two cells to the left of of the input cell (in columns AX and AY) will adopt the colors of the matching scheme.

    Let me know if you have any more issues or questions.

    (and, no...I don't work for Microsoft. I'm just fortunate that they noticed my work and granted me an MVP Award.)
    Attached Files Attached Files

  17. #17
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    wow!

    I like that Ron , not that I have any use for colour coding my files but the conciseness (to me anyway) & principles of your coding is great.

    If Stan is copying & pasting multiple torque values (target.rows.count>1) at once he will have problems with the colours because the Sheet Change code recolours the entire "target" not just "ccell'.
    You have acknowledged/allowed for this in your code for clearing the formatting but not in the code for applying the colour formatting.

    For Stan's benefit, this can be allowed for by changing...

    Please Login or Register  to view this content.

    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  18. #18
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Complex Conditional Formatting

    I should have caught that......Thanks.

  19. #19
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    no prob's :-)
    - Hopefully it solves Satchmo's problem.

    I was just being nosy, seeing what the content of the thread was that was causing such a large number of replies & happened to spot it.


    Rob

  20. #20
    Registered User
    Join Date
    10-31-2007
    Posts
    11
    Thanks both! Works great!!!!!!

+ 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