+ Reply to Thread
Results 1 to 22 of 22

VBA: Format cell colour within table sorted using slicer tools

  1. #1
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Unhappy VBA: Format cell colour within table sorted using slicer tools

    Hello all, I would like to format full table rows based on the text in column D after the table has been sorted using a slicer tool filtering on column C.



    In image 1 is the formatting I would like for the output (this has been manually formatted to show the different desired colours)
    Desired.jpg


    In image 2 is the problem, when filtered by column c (haulier) cells with the same colour end up 'next' to each other removing the clear delineation between sites.
    Problem.jpg

    Is the formatting that I want to do possible? It seems like it should be but currently I cannot make it do what I want.



    I have provided the spreadsheet with two tabs, tab one shows the desired, tab two the problem if that would help anyone.



    Many thanks


    GiantLegume
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-03-2016
    Location
    Catania, Italy
    MS-Off Ver
    Excel 2019
    Posts
    164

    Re: Format cell colour within table sorted using slicer tools

    Hello
    Select the affected range and in the conditional formatting enter this formula
    = MOD (D19; 3) = 1
    and assign the color you want.
    For the second color change the final 1 to 2

    Hello,
    Mario

  3. #3
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Format cell colour within table sorted using slicer tools

    Quote Originally Posted by Marius44 View Post
    Hello
    Select the affected range and in the conditional formatting enter this formula
    = MOD (D19; 3) = 1
    and assign the color you want.
    For the second color change the final 1 to 2

    Hello,
    Mario
    Hi Mario, I have tried that but nothing happens, have you tried it in my demonstration spreadsheet?

  4. #4
    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,807

    Re: Format cell colour within table sorted using slicer tools

    Try this:

    =MOD(D19,3)=1

    You need a comma for a UK locale, not Mario's semi-colon.
    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.

  5. #5
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Format cell colour within table sorted using slicer tools

    Quote Originally Posted by AliGW View Post
    Try this:

    =MOD(D19,3)=1

    You need a comma for a UK locale, not Mario's semi-colon.
    Hi Ali, that hasn't worked either. No formatting change in my spreadsheet.
    Have you tried it on my example spreadsheet? If so please would you share that one with me so I can see the working formula?

  6. #6
    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,807

    Re: Format cell colour within table sorted using slicer tools

    No - I am sitting in the garden away from my laptop.

    Did you select the whole range when you applied it?

  7. #7
    Forum Contributor
    Join Date
    09-03-2016
    Location
    Catania, Italy
    MS-Off Ver
    Excel 2019
    Posts
    164

    Re: Format cell colour within table sorted using slicer tools

    Hello
    I apologize for my mistake but in the Italian version we put a semicolon and not a comma. I forgot to correct.
    I am attaching the file I worked on.
    Hello,
    Mario
    Attached Files Attached Files

  8. #8
    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,807

    Re: Format cell colour within table sorted using slicer tools

    It doesn't work. The shading there is what the OP put there to demonstrate. Here's the file without the manual shading:

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    D
    E
    F
    G
    H
    18
    Site
    Species
    Length
    Diam
    Customer
    19
    Example 1
    Species 1
    3.7m
    20cm
    Customer 1
    20
    Example 1
    Species 1
    3.7m
    16cm
    Customer 2
    21
    Example 1
    Species 1
    3.7m
    16cm
    Customer 2
    22
    Example 1
    Species 1
    3.1m
    16cm
    Customer 2
    23
    Example 1
    Species 1
    2.5m
    14cm
    Customer 6
    24
    Example 1
    Species 2
    1.9m
    14cm
    Customer 2
    25
    Example 1
    Species 2
    3m
    7cm
    Customer 4
    26
    Example 1
    Species 2
    3m
    7cm
    Customer 4
    27
    Example 2
    Species 3
    3.7m
    16cm
    Customer 2
    28
    Example 2
    Species 3
    3.1m
    16cm
    Customer 2
    29
    Example 2
    Species 3
    2.5m
    14cm
    Customer 3
    30
    Example 2
    Species 3
    1.7/1.85m
    9cm
    Customer 8
    31
    Example 2
    Species 3
    3.7m
    11cm
    Customer 8
    32
    Example 2
    Species 3
    3m
    7cm
    Customer 4
    33
    Example 3
    Species 1
    4.3m
    16cm
    Customer 5
    34
    Example 3
    Species 1
    3.75m
    16cm
    Customer 5
    35
    Example 3
    Species 1
    3.1m
    18.5cm
    Customer 5
    36
    Example 3
    Species 1
    4.95m
    36cm
    Customer 2
    37
    Example 3
    Species 1
    2.5m
    14cm
    Customer 3
    38
    Example 3
    Species 1
    3m
    7cm
    Customer 4
    Sheet: Problem
    Attached Files Attached Files
    Last edited by AliGW; 05-18-2022 at 01:00 PM. Reason: Workbook attached.

  9. #9
    Forum Contributor
    Join Date
    09-03-2016
    Location
    Catania, Italy
    MS-Off Ver
    Excel 2019
    Posts
    164

    Re: Format cell colour within table sorted using slicer tools

    Hello
    My suggestion works, of course with the indicated fix.
    In FC you need to enter two formulas:
    1) = MOD (D19,3) = 1
    2) = MOD (D19,3) = 2
    and you will have the colors, which you will choose, alternating.
    Hello,
    Mario

  10. #10
    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,807

    Re: Format cell colour within table sorted using slicer tools

    Marius - please look at the attached and fix it, then post it back here. It is not working for me. Thanks.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    09-03-2016
    Location
    Catania, Italy
    MS-Off Ver
    Excel 2019
    Posts
    164

    Re: Format cell colour within table sorted using slicer tools

    Hello
    Please accept my apologies. You're absolutely right: first it worked (or, at least, I thought it worked) then it didn't work anymore.
    The correct formulas (in italian version) are these:
    =RESTO(VALORE(DESTRA($D19;1));2)>0
    =RESTO(VALORE(DESTRA($D19;1));2)=0
    which should become like this:

    =MOD(VALUE(RIGHT($D19,1)),2)>0
    =MOD(VALUE(RIGHT($D19,1)),2)=0


    and for each choose the color you like best.
    I hope this is the correct way. Let me know.
    Hello,
    Mario
    Last edited by AliGW; 05-19-2022 at 06:05 AM. Reason: Function name corrected.

  12. #12
    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,807

    Re: Format cell colour within table sorted using slicer tools

    Marius - please attach your sample workbook showing this. Thanks.

  13. #13
    Forum Contributor
    Join Date
    09-03-2016
    Location
    Catania, Italy
    MS-Off Ver
    Excel 2019
    Posts
    164

    Re: Format cell colour within table sorted using slicer tools

    Hello
    This is my workbook

    Hello,
    Mario
    Attached Files Attached Files

  14. #14
    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,807

    Re: Format cell colour within table sorted using slicer tools

    Thank you very much.

  15. #15
    Forum Contributor
    Join Date
    09-03-2016
    Location
    Catania, Italy
    MS-Off Ver
    Excel 2019
    Posts
    164

    Re: Format cell colour within table sorted using slicer tools

    Hello
    Since the data does not always have a final number but often it is text, perhaps it is better to change our approach.
    See the Sheets("Foglio1")
    Copy the range B2: B59 to another free area of ​​the sheet (I used column AA) and eliminate the duplicates.
    Then enter the following formulas in FC (one for each color)
    = OR ($ B2 = $ AA $ 2, $ B2 = $ AA $ 4, $ B2 = $ AA $ 6) for the first color
    = OR ($ B2 = $ AA $ 3, $ B2 = $ AA $ 5, $ B2 = $ AA $ 7) for the second color

    I attach my sample workbook showing this.
    Hello,
    Mario
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Format cell colour within table sorted using slicer tools

    Hello Mario and AliGW,

    Unfortunately I can't make any of the solutions listed above work once the data is filtered. What I am trying to do is format the table after the filters have been applied to make distinguishing between sites being serviced by the same haulier easier.
    Do you believe that this is possible? I am swimming out of my excel knowledge pool here and don't want to keep going if what I want to do isn't achievable.

    Thank you both for your efforts so far, I really appreciate the replies and my apologies for the delay in replying.

    Please let me know your thoughts and thanks again for taking the time.

    GiantLegume

  17. #17
    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,807

    Re: Format cell colour within table sorted using slicer tools

    Probably, but you may need VBA to do it.

  18. #18
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Format cell colour within table sorted using slicer tools

    Quote Originally Posted by AliGW View Post
    Probably, but you may need VBA to do it.
    Are there any good resources you can recommend for learning VBA?

  19. #19
    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,807

    Re: Format cell colour within table sorted using slicer tools

    How about I move this to the VBA section? Someone expert in code will be able to advise.

  20. #20
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Format cell colour within table sorted using slicer tools

    Quote Originally Posted by AliGW View Post
    How about I move this to the VBA section? Someone expert in code will be able to advise.
    If that's what you think would be best, I am happy to follow your lead.

  21. #21
    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,807

    Re: VBA: Format cell colour within table sorted using slicer tools

    I have moved the thread for you. Let's see what happens.

  22. #22
    Registered User
    Join Date
    05-18-2022
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA: Format cell colour within table sorted using slicer tools

    Hi Ali + all,

    Would a formatting rule like below work for what I want to do?

    Use if fortmatting
    If text in this cell is same as text above - format fill 'yellow'
    If text in this cell is different - format fill 'blue'
    Start conditional = if text above = 'site' format fill 'yellow'
    Apply to column D
    Use 'copy' format of cell to left for E>G

    Apologies if I haven't used the correct terms, still finding my way around.

    GiantLegume

+ 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: 4
    Last Post: 04-07-2022, 09:51 AM
  2. Use Cell Value as a Filter/Slicer Value for Pivot Table
    By Andrew-Mark in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-20-2020, 02:49 PM
  3. Replies: 1
    Last Post: 10-04-2019, 04:30 AM
  4. [SOLVED] colour of cell in table based on colour of same value cell elsewhere
    By tommy060289 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-10-2019, 05:50 AM
  5. Replies: 1
    Last Post: 04-23-2018, 09:43 AM
  6. [SOLVED] format a cell background colour based on a manual background colour of an adjacent cell
    By Nampara in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2018, 04:03 PM
  7. Replies: 0
    Last Post: 07-02-2013, 11:30 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