+ Reply to Thread
Results 1 to 14 of 14

Color cells in a table according to their Rows and Columns headers

  1. #1
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Color cells in a table according to their Rows and Columns headers

    Hi,

    I will appreciate your help in a required VBA solution:

    I have a table contains values with columns headers (above) and rows headers (at the left).

    I need to color all values cells in the table according to the combination of their Rows and Columns headers names. *** No matter what the cell's value is ***.

    Note that the are a few combinations of row & column header that code should refer to.

    For example:
    - For each cell that its row header name = "AAA" and its column header name = "JJJ", then color the cell background in Yellow.
    - For each cell that its row header name = "BBB" and its column header name = "KKK", then color the cell background in Green.
    - And etc....

    Else - Don't color the cell. Leave it as is.

    Note that the table changes in its number of Rows & Columns, so the code must support this action dynamically.

    Can you please advise how to write the code for this need?

    Thanks in advance
    Attached Files Attached Files
    Last edited by liorc13; 07-10-2019 at 03:50 AM. Reason: Add a sample of Excel workbook

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,806

    Re: Color cells in a table according to their Rows and Columns headers

    Will you please attach a sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    1. Make sure that your sample data are REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired results are also shown (mock up the results manually).

    3. Make sure that all confidential data is removed or replaced with dummy data first (e.g. names, addresses, E-mails, etc.).

    4. Try to avoid using merged cells as they cause lots of problems.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

    Please pay particular attention to point 2 (above): without an idea of your intended outcomes, it is often very difficult to offer appropriate advice.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Thanks a lot Ali for your clarifications.
    I'll act accordingly.

    Thanks

  4. #4
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Added to my thread a sample Excel Workbook.

    Thanks.

  5. #5
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Color cells in a table according to their Rows and Columns headers

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  6. #6
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Thanks a lot KOKOSEC, but I have a question regarding the dynamic range:
    As I said, I need that the range will be dynamic since columns and row numbers change. Which VBA command in this case do I need to use for range to be declared dynamically?

    Thanks

  7. #7
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Color cells in a table according to their Rows and Columns headers

    This would work on a dynamic range and also clear out any previous colouring on the cells:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  8. #8
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Color cells in a table according to their Rows and Columns headers

    Quote Originally Posted by liorc13 View Post
    Which VBA command in this case do I need to use for range to be declared dynamically?
    Thanks

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Thanks a lot KOKOSEC! It works perfect!
    Appreciate your help
    Last edited by liorc13; 07-10-2019 at 11:25 AM.

  10. #10
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Thanks a lot WBD

  11. #11
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Color cells in a table according to their Rows and Columns headers

    Quote Originally Posted by liorc13 View Post
    Thanks a lot KOKOSEK! It works perfect!
    If you don't mind.
    You welcome.
    Happy to help.

  12. #12
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Of course KOKOSEK, with pleasure! You deserve it

    Thanks again!
    Last edited by liorc13; 07-11-2019 at 01:08 AM.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,806

    Re: Color cells in a table according to their Rows and Columns headers

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

  14. #14
    Registered User
    Join Date
    04-21-2016
    Location
    Israel
    MS-Off Ver
    Office 2016
    Posts
    52

    Re: Color cells in a table according to their Rows and Columns headers

    Marked as SOLVED.

    Thanks for the notice.

+ 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. Apply fill color to block of cells on each sheet. Columns always the same, rows will vary
    By carlito2002wgn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2019, 11:45 AM
  2. Replies: 2
    Last Post: 11-24-2017, 03:51 PM
  3. Power Pivot table headers changes color when refreshed
    By Sgligori in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-19-2015, 03:56 PM
  4. Macro to copy rows based on background color of cells within a range of columns
    By jpitt916 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2013, 06:16 PM
  5. [SOLVED] Macro to copy rows based on background color of cells within a range of columns
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-19-2013, 01:30 PM
  6. Finding Headers in a Table with Multiple Columns/Rows
    By CST in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-19-2010, 09:18 AM
  7. How do I change color of cells, columns and rows in Excel?
    By Johnny434 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 07-11-2006, 10:00 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