VBA - Sum Cell Contents Based Color

Liz2212

New Member
Joined
Jun 3, 2015
Messages
4
I have conditional formatting setup to highlight 3 different sets of data based on specific date ranges. I am looking for some way to be able to sum all the cells that have one of the different color highlights. I assume this can be completed using VBA, but I have been unable to find the appropriate code that works for conditional formatting.
Thanks.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Upvote 0
However, if the color is determined by Conditional Formatting, then you can use the same Formulas you used there in SUMIF or SUMIFS formulas to return the total for each color.
See: https://www.ablebits.com/office-addins-blog/2014/11/12/excel-sumifs-sumif-multiple-criteria/

Thanks for the reply Joe. I tried to use the sumif formula to return the sum using the same formula I used for conditional formatting, but the conditional formatting is setup on approx. every 3rd column for 360 columns and the formula didn't return the number correctly and was very cumbersome. I pasted the sumif formula I tried to use below:
=SUMIF((F:F,I:I,L:L,O:O,R:R,U:U,X:X,AA:AA,AD:AD,AG:AG,AJ:AJ,AM:AM,AP:AP,AS:AS,AV:AV,AY:AY,BB:BB,BE:BE,BH:BH,BK:BK,BN:BN,BQ:BQ,BT:BT,BW:BW,BZ:BZ,CC:CC,CF:CF,CI:CI,CL:CL,CO:CO,CR:CR,CU:CU,CX:CX,DA:DA,DD:DD,DG:DG,DJ:DJ,DM:DM,DP:DP,DS:DS,DV:DV,DY:DY,EB:EB,EE:EE,EH:EH,EK:EK,EN:EN,EQ:EQ,ET:ET,EW:EW,EZ:EZ,FC:FC,FF:FF,FI:FI,FL:FL,FO:FO,FR:FR,FU:FU,FX:FX,GA:GA,GD:GD,GG:GG,GJ:GJ,GM:GM,GP:GP,GS:GS,GV:GV,GY:GY,HB:HB,HE:HE,HH:HH,HK:HK,HN:HN,HQ:HQ,HT:HT,HW:HW,HZ:HZ,IC:IC,IF:IF,II:II,IL:IL,IO:IO,IR:IR,IU:IU),AND(F7<>0,D$6<=($B7+28)),(F:F,I:I,L:L,O:O,R:R,U:U,X:X,AA:AA,AD:AD,AG:AG,AJ:AJ,AM:AM,AP:AP,AS:AS,AV:AV,AY:AY,BB:BB,BE:BE,BH:BH,BK:BK,BN:BN,BQ:BQ,BT:BT,BW:BW,BZ:BZ,CC:CC,CF:CF,CI:CI,CL:CL,CO:CO,CR:CR,CU:CU,CX:CX,DA:DA,DD:DD,DG:DG,DJ:DJ,DM:DM,DP:DP,DS:DS,DV:DV,DY:DY,EB:EB,EE:EE,EH:EH,EK:EK,EN:EN,EQ:EQ,ET:ET,EW:EW,EZ:EZ,FC:FC,FF:FF,FI:FI,FL:FL,FO:FO,FR:FR,FU:FU,FX:FX,GA:GA,GD:GD,GG:GG,GJ:GJ,GM:GM,GP:GP,GS:GS,GV:GV,GY:GY,HB:HB,HE:HE,HH:HH,HK:HK,HN:HN,HQ:HQ,HT:HT,HW:HW,HZ:HZ,IC:IC,IF:IF,II:II,IL:IL,IO:IO,IR:IR,IU:IU))

It is possible that my criteria is incorrectly written for the sumif but regardless my range cannot be a solid range and is very difficult to work with. I am looking for some way to get the sum with a much simpler formula and thought VBA might be able to provide that.
Thanks.
 
Upvote 0
If you formulas are that complex, I would probably go with the VBA UDF options outlined in the other link I provided.
 
Upvote 0
I just tried using those VBA UDF options but couldn't get them to work with the conditional formatted highlighted cells. Is there an adjustment I can make to account for conditional formatting or would my only option be to go through and manually fill all the colored cells?
Thanks.
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

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