How to count color cells using countif with vba

lovejanu4u

New Member
Joined
Apr 29, 2019
Messages
36
Please anyone comment and provide the information.
Appreciated and thanks in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You can also create a custom function with VBA to count highlighted cells in Excel. To do that you need to create a custom function using VBA that works like a COUNTIF function and returns the number of cells for the same color.

You will follow the syntax: =CountFunction(CountColor, CountRange) and use it like other regular functions.Here CountColor is the color for which you want to count the cells. CountRange is the range in which you want to count the cells with the specified background color.
 
Upvote 0
You can also create a custom function with VBA to count highlighted cells in Excel. To do that you need to create a custom function using VBA that works like a COUNTIF function and returns the number of cells for the same color.

You will follow the syntax: =CountFunction(CountColor, CountRange) and use it like other regular functions.Here CountColor is the color for which you want to count the cells. CountRange is the range in which you want to count the cells with the specified background color.
Thanks for the information @montecarlo2012

Can I have the code as well.
 
Upvote 0
The problem is that changing a cell's color does not trigger Calculation or any VB event. If you write a UDF like this, it will have to be volatile and you will need to manually force calculation to insure that the result is current and accurate.

The other issue is where the cells get their color. If it is set by the user, then all those objections apply. If the color is set by conditional formatting, it would be better to test the format conditions rather than testing the color of the cell.
 
Upvote 0
The problem is that changing a cell's color does not trigger Calculation or any VB event. If you write a UDF like this, it will have to be volatile and you will need to manually force calculation to insure that the result is current and accurate.

The other issue is where the cells get their color. If it is set by the user, then all those objections apply. If the color is set by conditional formatting, it would be better to test the format conditions rather than testing the color of the cell.


Thank you @mikerickson for the information.
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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