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.
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,935
Office Version
  1. 365
Platform
  1. Windows

Liz2212

New Member
Joined
Jun 3, 2015
Messages
4
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,935
Office Version
  1. 365
Platform
  1. Windows
If you formulas are that complex, I would probably go with the VBA UDF options outlined in the other link I provided.
 

Liz2212

New Member
Joined
Jun 3, 2015
Messages
4

ADVERTISEMENT

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,686
Messages
5,597,536
Members
414,153
Latest member
SandraC

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
Top