+ Reply to Thread
Results 1 to 7 of 7

Automatically color-code cells in one sheet based on values matched from another sheet

  1. #1
    Registered User
    Join Date
    10-23-2023
    Location
    Stockholm, Sweden
    MS-Off Ver
    MS Windows 10 Enterprise. Excel for Microsoft 365 MSO (V.2302 Build 16.0.16130.20806) 32-bit
    Posts
    11

    Automatically color-code cells in one sheet based on values matched from another sheet

    I have a situation with color-shading certain cells in Excel which I hope someone in the Forum can help me with.

    I have three sheets in an excel file (attached).

    Sheet 1 ("Main Stats") contains the summary statistics of the number of insurance payments broken down by group, payment type (DC or DB) and agreement type. Note in the example, there are just 3 groups but in reality there are hundreds, as each group represents a different geographic area.

    Sheets 2 & 3 (called "Defined Contribution - DC" and "Defined Benefit - DB" respectively) contain the agreement types themselves, associated with each payment type.

    Note, that "DC" payments are colored in yellow in the Main Stats sheet, and "DB" payments are in green -- both which I've done manually for this example.

    My goal: I want to be able to display the agreement stats associated with each payment type using the color found in the DC or DB sheets, but automatically instead of manually.

    Is there a way using VBA on "Main Stats" to programmatically look at the agreement type in cols B through G from Row 6 on down,
    and, after matching it with appropriate Payment type sheet (DC or DB), apply the correct color to these cells?

    Any help, hints or advice would be much appreciated.

    Jeff
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Automatically color-code cells in one sheet based on values matched from another sheet

    Why do you need VBA? You could us Conditional Formatting with a simple COUNTIF formula.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Automatically color-code cells in one sheet based on values matched from another sheet

    Please Login or Register  to view this content.
    Also calculates totals in row 4

    Any reason for not putting DC/DB in the same sheet (adding another column with DC or DB if required) ? This will enable a simple Conditional Formatting solution as per reply from TMS in post #2
    Attached Files Attached Files
    Last edited by JohnTopley; 01-07-2024 at 03:49 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Automatically color-code cells in one sheet based on values matched from another sheet

    @JT: still two conditions

  5. #5
    Registered User
    Join Date
    10-23-2023
    Location
    Stockholm, Sweden
    MS-Off Ver
    MS Windows 10 Enterprise. Excel for Microsoft 365 MSO (V.2302 Build 16.0.16130.20806) 32-bit
    Posts
    11

    Re: Automatically color-code cells in one sheet based on values matched from another sheet

    Thank you TMS and JohnTopley for your helpful replies. I will try to use Conditional Formatting with a COUNTIF, as it would be easier to maintain. If I don't acheive that, then I will revert to JohnTopley's VBA solution he so kindly provided. Much appreciated help!
    Jeff

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Automatically color-code cells in one sheet based on values matched from another sheet

    You're welcome. Thanks for the rep.

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Automatically color-code cells in one sheet based on values matched from another sheet

    Thanks from me too for the rep.

+ 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. Automatically change sheet tab color based on sheet name
    By tmcwade in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2023, 02:30 PM
  2. [SOLVED] split data into two sheets matched & not matched based on matching sheet
    By abdo meghari in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-31-2022, 02:24 PM
  3. Sheet tab color update based of range on values on sheet 1
    By Prascena in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-11-2021, 10:37 AM
  4. [SOLVED] Vba code to color text in sheet 1 based on key words present in next sheet.
    By sapnawat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2018, 04:26 AM
  5. Automatically sort cells in one sheet based on values in another
    By tubells in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 03-10-2016, 12:24 PM
  6. [SOLVED] Dynamically color cell on Summary sheet based on column values on data sheet
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-08-2016, 12:59 PM
  7. Change cell colour, based on matched cells in sheet 2
    By Bobbo Jones in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-14-2013, 02:27 AM

Tags for this Thread

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