+ Reply to Thread
Results 1 to 8 of 8

Conditional Formatting based on Sum

  1. #1
    Registered User
    Join Date
    05-20-2016
    Location
    Toronto, Canada
    MS-Off Ver
    365
    Posts
    24

    Conditional Formatting based on Sum

    Hi all,

    Thanks in advance for any help!

    I have a pivot table that has Item Location and Qty on Hand, grouped by Item and sorted descending by Qty.
    I am trying to consolidate the locations that have a small amount into a single location.
    What I want is to highlight within each (item) group from the smallest quantity and up until the sum of these locations is equal to or less than the maximum
    (which is the first item in each group). The challenge is each group may contain different number of locations (rows).

    Sample attached.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Conditional Formatting based on Sum

    Hi AlanaT,
    for the first group your function in the conditional format = =SUM(C2:C$14)<=C$2 and copy this format to the end of the group
    for the second group it is: =SUM(C16:C$51)<=C$16
    and third: =SUM(C53:C$91)<=C$53

    Cheers
    Eastw00d
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Registered User
    Join Date
    05-20-2016
    Location
    Toronto, Canada
    MS-Off Ver
    365
    Posts
    24

    Re: Conditional Formatting based on Sum

    Hi Eastw00d,

    Thank you for this help! Does this require that I enter this conditional formatting (a different formula) for each group?
    My upload was only a sample. My actual data file has hundreds of groups. Is there a way to do them all in one step/Macro/other?

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

    Re: Conditional Formatting based on Sum

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 03-17-2023 at 03:38 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Conditional Formatting based on Sum

    @JohnTopley: a very nice solution!

    Cheers
    Eastw00d

  6. #6
    Registered User
    Join Date
    05-20-2016
    Location
    Toronto, Canada
    MS-Off Ver
    365
    Posts
    24

    Re: Conditional Formatting based on Sum

    @JohnTopley

    This is fabulous! However, I keep getting a runtime error and when I hit debug this line is highlighted: Range("C" & srow).Resize(lr - srow, 1).Interior.ColorIndex = 20
    I think the problem exists if the "group" has only 1 or 2 locations, as there aren't enough to sum to compare to the max??

  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,148

    Re: Conditional Formatting based on Sum

    I did a test with 3 locations with values of 420/200/20 and it highlighted 200/20 but no error. You will get an error if there is only ONE location.

    Please Login or Register  to view this content.
    Last edited by JohnTopley; 03-21-2023 at 04:54 PM.

  8. #8
    Registered User
    Join Date
    05-20-2016
    Location
    Toronto, Canada
    MS-Off Ver
    365
    Posts
    24

    Re: Conditional Formatting based on Sum

    @ JohnTopley

    This works!! I still get the error, but now when I debug, I just move the arrow to the "On Error Resume Next" line and continue (F5). Works like a charm. Thank you!

+ 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] Conditional Formatting based on another cells Conditional Formatting
    By chriskay in forum Excel General
    Replies: 4
    Last Post: 08-22-2019, 05:33 AM
  2. Replies: 1
    Last Post: 10-04-2016, 05:17 AM
  3. Replies: 1
    Last Post: 08-19-2016, 03:57 PM
  4. Macro to set up conditional message based on results of conditional formatting
    By paysola in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-04-2016, 12:38 AM
  5. Replies: 1
    Last Post: 09-20-2013, 06:23 PM
  6. Conditional Formatting via VBA: Change formatting in range based on value of each cell
    By ralphjmedia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2013, 10:37 AM
  7. Replies: 4
    Last Post: 01-06-2012, 05:07 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