+ Reply to Thread
Results 1 to 6 of 6

Color scale conditional formatting based on another cell's value

  1. #1
    Registered User
    Join Date
    11-23-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Color scale conditional formatting based on another cell's value

    Hi

    I'm trying to have a value displayed in a cell, but have a graded colourscale based on other cells values. Any pointers would be greatly appreciated. I've knocked up an example attached by changing the number format, but i don't think that's a particularly good way of doing it.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Color scale conditional formatting based on another cell's value

    Hi,

    This code, placed in the worksheet code section of your file (not a module and not the workbook), will do it:
    Please Login or Register  to view this content.
    The first bit of the code means that the code will only run when something changes in the G4:I6 range. If you've got multiple ranges, I think you can put in multiple copies of this code, referring to different ranges, each of which will then only activate if those particular ranges are amended - but I'm not 100% sure about that...
    I tried to do one line with Range("B4:D6") and Range("G4:I6") but for some reason that changed B4:D6 all to black fill - so I've had to put in one line for each cell.
    There's probably someone on here who can come up with a more efficient way of doing this, as I'm not very good with VBA, but at least this works.

    Here's your file with this macro in it: CF colour scale based on values in other range _ for johnharrison.xlsm
    I've reset the fill to 'no fill' so that you can see it work - just change any cell in the right-hand table (typing the same value again will work) and you'll see the left-hand table colours change to match, as you want.

    Hope that's of some help.
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

  3. #3
    Registered User
    Join Date
    11-23-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    4
    Ahhhhhhhhh of course. So simple now you've pointed it out. Thanks so much for your help.




    Quote Originally Posted by Aardigspook View Post
    Hi,

    This code, placed in the worksheet code section of your file (not a module and not the workbook), will do it:
    Please Login or Register  to view this content.
    The first bit of the code means that the code will only run when something changes in the G4:I6 range. If you've got multiple ranges, I think you can put in multiple copies of this code, referring to different ranges, each of which will then only activate if those particular ranges are amended - but I'm not 100% sure about that...
    I tried to do one line with Range("B4:D6") and Range("G4:I6") but for some reason that changed B4:D6 all to black fill - so I've had to put in one line for each cell.
    There's probably someone on here who can come up with a more efficient way of doing this, as I'm not very good with VBA, but at least this works.

    Here's your file with this macro in it: Attachment 423927
    I've reset the fill to 'no fill' so that you can see it work - just change any cell in the right-hand table (typing the same value again will work) and you'll see the left-hand table colours change to match, as you want.

    Hope that's of some help.

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Color scale conditional formatting based on another cell's value

    You're welcome and thanks for the rep.

  5. #5
    Registered User
    Join Date
    10-18-2016
    Location
    Paris, France
    MS-Off Ver
    2010
    Posts
    2

    Re: Color scale conditional formatting based on another cell's value

    Hi,

    Just for good measure, here's a more compact version of that VBA code.

    Please Login or Register  to view this content.
    This macro has to be actually run to color the cells in, it doesn't do it automatically. I didn't even know you could do that. I bet someone more clever than I could merge both codes into a beautiful diamond of efficiency.
    Last edited by Inasmuch; 10-19-2016 at 03:47 AM. Reason: Added code tags around code

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Color scale conditional formatting based on another cell's value

    Inasmuch, please put code tags around you code before someone comes along and posts this obnoxious BS...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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] Color scale conditional formatting based on another cell's value
    By dtrimble in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-29-2024, 09:49 AM
  2. Conditional Color Scale Formatting Not Working
    By Merf in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2015, 10:03 AM
  3. 3-Color-Scale Conditional Formatting
    By savetrees in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-05-2015, 08:45 AM
  4. [SOLVED] Conditional Formatting like Color Scale but doing it via Interior.Color
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2015, 06:36 AM
  5. Color Scale Conditional Formatting
    By dev.jajati in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-12-2014, 04:10 AM
  6. Help with conditional formatting 3 color scale
    By ab0mbs in forum Excel General
    Replies: 1
    Last Post: 09-24-2013, 12:43 PM
  7. Conditional Formatting 3 color scale
    By Kagesen in forum Excel General
    Replies: 15
    Last Post: 05-03-2012, 08:50 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