Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

How to count only visible cells in a custom function (count cells based on cell colour)

$
0
0

I am using a custom function that I found on the net. It does what I need it to do - counts cells of specific colour in a range of cells.

How do I edit it to only count visible cells? I have tried to use this, but it doesn't doo anything.

For Each rCell In CountRange.SpecialCells(xlCellTypeVisible)

Complete function is this:

    Function GetColorCount(CountRange As Range, CountColor As Range, Optional VolatileParameter As Variant)
Dim CountColorValue As Integer
Dim TotalCount As Integer
CountColorValue = CountColor.Interior.ColorIndex
Set rCell = CountRange
For Each rCell In CountRange
  If rCell.Interior.ColorIndex = CountColorValue Then
    TotalCount = TotalCount + 1
  End If
Next rCell
GetColorCount = TotalCount
End Function

To use it in the worksheet I then type:

=GetColorCount(A1:G20,H1, NOW())

Where:

  • A1:G20 is the range I want to count all yellow cells
  • H1 is cell where count is displayed and is coloured in yellow
  • NOW() makes it run everytime a change is made in the range (??)

Any tips?


Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>