ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Count if a cell has color shading (https://www.excelbanter.com/excel-discussion-misc-queries/156467-count-if-cell-has-color-shading.html)

robnsd

Count if a cell has color shading
 
Is there a way to count a cell if it has color shading? I have no
values in my cells, but they are either shaded a color or not. I only
want to count the cells that have color shading in the range I select.
Is this possible? I would rather not enter values or text in the cells
to count them.


ExcelBanter AI

Answer: Count if a cell has color shading
 
Yes, it is possible to count cells based on their color shading in Excel. Here are the steps to do so:
  1. Select the range of cells that you want to count.
  2. Click on the Home tab in the ribbon.
  3. Click on the Conditional Formatting button and select New Rule.
  4. In the New Formatting Rule dialog box, select Use a formula to determine which cells to format.
  5. In the Format values where this formula is true field, enter the following formula:
    Formula:

    =CELL("color",A1)

    (Note: Replace A1 with the top-left cell of your selected range)
  6. Click on the Format button and select the color that you want to count.
  7. Click OK to close the Format Cells dialog box.
  8. Click OK to close the New Formatting Rule dialog box.

Now, the cells with the selected color shading will be highlighted. To count them, use the following formula:

Formula:

=COUNTIF(range,CELL("color",A1)0

(Note: Replace "range" with the range of cells you want to count, and replace A1 with the top-left cell of that range)

This formula will count the number of cells in the selected range that have color shading.

Bob Phillips

Count if a cell has color shading
 
See http://www.xldynamic.com/source/xld.ColourCounter.html for a working
solution

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"robnsd" wrote in message
oups.com...
Is there a way to count a cell if it has color shading? I have no
values in my cells, but they are either shaded a color or not. I only
want to count the cells that have color shading in the range I select.
Is this possible? I would rather not enter values or text in the cells
to count them.




jlclyde

Count if a cell has color shading
 
On Aug 30, 1:01 pm, robnsd wrote:
Is there a way to count a cell if it has color shading? I have no
values in my cells, but they are either shaded a color or not. I only
want to count the cells that have color shading in the range I select.
Is this possible? I would rather not enter values or text in the cells
to count them.


Function CountColor(Color As Range, Range As Range) As Long
Dim C As Range
For Each C In Range
If C.Interior.ColorIndex = Color.Interior.ColorIndex Then
CountColor = CountColor + 1
End If
Next
End Function

I do not knwo how much you know about VBA so here goes. I am assumign
that you want to use this function on multiple workbooks and not just
the one right now. You will need to save this function to your
personel macro work book. To do this you need to go to tools, Macro,
record new macro, choose personel macro workbook, Hit the little stop
button or go to tools macro stop. Go to Window, Unhide, personel
macro workbook. As it is unhid click Alt+F11. This will open the VBA
window. Insert Module. Highlight the function from this posting and
copy into your module.
To use the formula type =COUNTCOLOR( Then click on cell color that
you want to know the count of, Click the range that you want to
count.
Jay



All times are GMT +1. The time now is 07:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com