Advanced Conditional Formatting for non-repetitive patterns using VBA code

crmau

New Member
Joined
Oct 29, 2015
Messages
19
Hello,

I haven't been able to figure out how to color 7 different ways a total number of rows automatically with a VBA code.

So basically I work on a client report on a daily basis that has 20,000+ rows. Once I've filtered it and hidden unnecessary rows, it comes down to around 1,000 rows. One client can have multiple transactions, so for example one client could account for 50 rows and another client for 3 rows. I've figured out a way already to count the unique number of clients that appear on the ~1,000 rows, which comes to about 160 unique clients.

I need to divide the total number of clients by 7 and have my macro fill-color those rows differently (yellow, light green, dark green, orange, blue, brown, purple). My problems are:

1. I usually never get a number that can be evenly divided by 7. We can use 160/7=22.86 as an example.

2. Using the above number, let's just round that to 23. I would highlight my first 23 UNIQUE clients with yellow. But those 23 clients could be 23 rows one day or 500 rows another day, depending on the number of transactions that those clients made.

Therefore, I really have no idea on how to make Excel count, divide and color 7 different ways my data.

Any help/input is appreciated! Let me know if you have questions!

This is my counting formula in case you find it useful:

Code:
' Count Unique Clients

    ' Define Rge as the column A range without the header

    ActiveWorkbook.Names.Add Name:="Rge", RefersTo:= _
        ActiveSheet.Range("A2:A50000")
        
    ' Define unRge as a formula

    ActiveWorkbook.Names.Add Name:="unRge", RefersToR1C1:= _
        "=IF(SUBTOTAL(3,OFFSET(Rge,ROW(Rge)-MIN(ROW(Rge)),,1)),Rge,"""")"
    ActiveWorkbook.Names("unRge").Comment = ""

    ' Count the unique number of CIDs that are NOT hidden

    Range("AE1").Select
    Selection.FormulaArray = _
        "= SUM(N(IF(ISNA(MATCH("""",unRge,0)),MATCH(Rge,Rge,0),IF(MATCH(unRge,unRge,0)=MATCH("""",unRge,0),0,MATCH(unRge,unRge,0)))=ROW(Rge)-MIN(ROW(Rge))+1))"
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,247
Messages
6,123,857
Members
449,129
Latest member
krishnamadison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top