ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Worksheet formulas (https://www.excelbanter.com/excel-worksheet-functions/143989-worksheet-formulas.html)

Thomas

Worksheet formulas
 
What formula enables me to count the number of cells with a specific format?

Bob Phillips

Worksheet formulas
 
None.

Function CountEm(rng as range, cellFormat as string)
Dim cell As Range
For each cell in rng
If cell.numberformat = cellformat Then
CountEm = CountEm + 1
End If
Next cell
End Function

--
HTH

Bob

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

"Thomas" wrote in message
...
What formula enables me to count the number of cells with a specific
format?




ryguy7272

Worksheet formulas
 
Hey Bob! I just noticed your code. I copied/pasted it into a VBA module and
tried to get it working, but was unable to do so. I tried the version that
Chip Pearson posed on his site:

http://www.cpearson.com/excel/colors.htm

This works well for me, but yours does not.

I colored cells A1:A2 & A4:A6, and colored cell C1 the same color (cells
A3:A4 are white).Then I placed =countem(A1:A6,C1) in E1 and I expected to see
a value of 4, but instead I got a value of 6. If you get a chance, please
explain how to €˜call your function.

Regards,
Ryan---
--
RyGuy


"Bob Phillips" wrote:

None.

Function CountEm(rng as range, cellFormat as string)
Dim cell As Range
For each cell in rng
If cell.numberformat = cellformat Then
CountEm = CountEm + 1
End If
Next cell
End Function

--
HTH

Bob

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

"Thomas" wrote in message
...
What formula enables me to count the number of cells with a specific
format?





Bob Phillips

Worksheet formulas
 
This was not for cell colour, but cell formats.

--
HTH

Bob

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

"ryguy7272" wrote in message
...
Hey Bob! I just noticed your code. I copied/pasted it into a VBA module
and
tried to get it working, but was unable to do so. I tried the version
that
Chip Pearson posed on his site:

http://www.cpearson.com/excel/colors.htm

This works well for me, but yours does not.

I colored cells A1:A2 & A4:A6, and colored cell C1 the same color (cells
A3:A4 are white).Then I placed =countem(A1:A6,C1) in E1 and I expected to
see
a value of 4, but instead I got a value of 6. If you get a chance, please
explain how to 'call' your function.

Regards,
Ryan---
--
RyGuy


"Bob Phillips" wrote:

None.

Function CountEm(rng as range, cellFormat as string)
Dim cell As Range
For each cell in rng
If cell.numberformat = cellformat Then
CountEm = CountEm + 1
End If
Next cell
End Function

--
HTH

Bob

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

"Thomas" wrote in message
...
What formula enables me to count the number of cells with a specific
format?








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

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