View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Hutchins Tom Hutchins is offline
external usenet poster
 
Posts: 1,069
Default Count merged cells as if unmerged

Try this:

Public Function CountColors(ColorNbr As String) As Long
Dim lCount As Long, c As Range
lCount = 0
For Each c In Range("ThisRange")
If c.Interior.color = ColorNbr Then
If c.MergeCells = True Then
lCount = lCount + c.Count
Else
lCount = lCount + 1
End If
End If
Next c
CountColors = lCount
End Function

Sub TEST()
MsgBox CountColors("825735")
End Sub

Hope this helps,

Hutch

"John" wrote:

I had this neat macro that counts how many cells are a certain color:



Public Function CountColors(color As String) As Integer

Dim intCount As Integer

Dim cell As Range



For Each cell In Range("ThisRange").Cells

If cell.Interior.color = 825735 Then intCount = intCount + 1

Next cell

CountColors = intCount

End Function



The problem is, I have merged some cells. How can I get a macro to count
say, 3 cells merged into 1 as three cells, not 1, if they match a certain
color?.