VBA code counting the nbr of cells with a certain color ?

gaftalik

Well-known Member
Joined
Feb 6, 2003
Messages
521
Office Version
  1. 2016
Platform
  1. Windows
Hi ,

Is there any VBA code which counts the nbr of cells with a certain color ? and not the sum of the values of cells with a certain color!:roll:

Thank you
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Re: VBA code counting the nbr of cells with a certain color

Yup! Check out http://www.cpearson.com/excel/colors.htm and

Rich (BB code):
Function CountColor(rColor As Range, rSumRange As Range) 

'''''''''''''''''''''''''''''''''''''' 
' Written by Ozgrid Business Applications 
' www.ozgrid.com 
' http://www.ozgrid.com/VBA/Sum.htm 
' Counts cells based on a specified fill color. 
''''''''''''''''''''''''''''''''''''''' 
Dim rCell As Range 
Dim iCol As Integer 
Dim vResult 

iCol = rColor.Interior.ColorIndex 

   For Each rCell In rSumRange 
    If rCell.Interior.ColorIndex = iCol Then 
         vResult = vResult + 1 
    End If 
   Next rCell 

CountColor = vResult 
End Function

HTH
 
Upvote 0
Re: VBA code counting the nbr of cells with a certain color

I copied that and i went to userdefined functions and i didnt see the formula , what shall the formula be ?
 
Upvote 0
You need to put the code in a module, not the Sheets/ThisWorkbook projects.

It should show up in the list then.
 
Upvote 0
Re: VBA code counting the nbr of cells with a certain color

That was really a mistake :wink: , thank you all very much :bow:
 
Upvote 0

Forum statistics

Threads
1,226,618
Messages
6,192,052
Members
453,693
Latest member
maverick688

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