+ Reply to Thread
Results 1 to 6 of 6

Excel VBA Color cells inside a table that contains value

  1. #1
    Registered User
    Join Date
    01-13-2021
    Location
    Sweden
    MS-Off Ver
    Office365
    Posts
    6

    Post Excel VBA Color cells inside a table that contains value

    Hello everyone.
    First of all, I’m a VBA rookie, so please bear with me
    This is what I’m trying to do:
    I have one sheet (Sales) with a table (Table1) that looks like this.
    Sales.jpg

    What I’m trying to achieve is to set a specific background color to every third row, except for cells that don’t have a value.
    The background color is based on the brand name (in column 2). The color for each brand is stipulated from another sheet (Colors) that looks like this:

    Colors.jpg

    I found this code online that colors every third row as I want. But as you can see in the code it colors the whole row, so I added a macro to clear
    all the cells inside the table without a value.
    But it’s really slow and gets slower for every brand that’s added to the table.

    I guess there’s a much better and smarter way to do this, but it’s beyond my knowledge
    and I hope I can get some help and guidance to make the script work better
    Thanks!


    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    01-12-2021
    Location
    South Africa
    MS-Off Ver
    Office 2016
    Posts
    18

    Re: Excel VBA Color cells inside a table that contains value

    Hi Rob

    Why don't you use conditional formatting, much better than vb coding.

  3. #3
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Excel VBA Color cells inside a table that contains value

    Try this code, you don't need to run the clear empty cells code, so it should run faster

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-13-2021
    Location
    Sweden
    MS-Off Ver
    Office365
    Posts
    6

    Re: Excel VBA Color cells inside a table that contains value

    Hi Ramirez.
    The challenge is that the table contain over 50 brands right now, and new brand will be added frequently.
    So I would prefer to just be able to add a Brand and Color to the list, instead of having to alter the code every time a brand is added.

  5. #5
    Registered User
    Join Date
    01-13-2021
    Location
    Sweden
    MS-Off Ver
    Office365
    Posts
    6

    Re: Excel VBA Color cells inside a table that contains value

    Hi maniacb.
    Thanks for the response.
    I also like the sales numbers to be colored in every third row, but if I extend the offset to cover the sales number, the empty also gets colored, is there’s away round that?

  6. #6
    Registered User
    Join Date
    01-12-2021
    Location
    South Africa
    MS-Off Ver
    Office 2016
    Posts
    18

    Re: Excel VBA Color cells inside a table that contains value

    Hi Rob

    For this request of yours i would still go for conditional formatting. When you make any entry in column B then the row will be highlighted.
    Attached Files Attached Files

+ 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. Replies: 8
    Last Post: 10-08-2020, 01:34 PM
  2. Replies: 0
    Last Post: 09-11-2019, 10:22 AM
  3. Problems exporting a table - find/replace data inside a table in word through excel vba
    By elvagonumero1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2018, 04:33 PM
  4. [SOLVED] delete entire active cells row/s only if thet all inside of a table (whatever table it is)
    By netanel99 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-02-2017, 01:42 PM
  5. [SOLVED] Excel 2010 - use a formula on a pivot table values to color cells on the column next to it
    By ofirmarco in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-08-2016, 12:30 PM
  6. How to remove horizontal lines from inside table cells?
    By Reema in forum Word Formatting & General
    Replies: 4
    Last Post: 07-20-2009, 04:10 AM
  7. highlight/color cells with specific character inside
    By markx in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-20-2005, 06:05 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