ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Count cells by format (https://www.excelbanter.com/excel-worksheet-functions/123851-count-cells-format.html)

GeneR

Count cells by format
 
Is there a way to count/sum cells by their formatting? For example, could I
count or sum the number of cells that are "Highlighted" or that the text was
"Bold"?

[email protected]

Count cells by format
 
Gene

You could create a function that would do what you want. For example,
to count the cells in a range that are bold, this should work

Function test(R1)
Application.Volatile

For Each cl In R1

If cl.Font.Bold = True Then
Count = Count + 1
End If

Next cl
test = Count
End Function

If on your spreadsheet you enter =test(range) in a cell, the cell value
will be the number of bold cells in the range. The
"application.volatile" causes the UDF to calculate when the worksheet
recalculates, but, simply changing the font to bold in a cell doesn't
trigger the recalc. You could change the If loop to coutn or sum
pretty much anything you want.

Good luck.

Ken
Norfolk, Va



GeneR wrote:
Is there a way to count/sum cells by their formatting? For example, could I
count or sum the number of cells that are "Highlighted" or that the text was
"Bold"?



GeneR

Count cells by format
 
Ken,

I certainly appreciate the help, but I think you lost me somewhere. Is
there an example or something in a little more plan language you could show
me?

" wrote:

Gene

You could create a function that would do what you want. For example,
to count the cells in a range that are bold, this should work

Function test(R1)
Application.Volatile

For Each cl In R1

If cl.Font.Bold = True Then
Count = Count + 1
End If

Next cl
test = Count
End Function

If on your spreadsheet you enter =test(range) in a cell, the cell value
will be the number of bold cells in the range. The
"application.volatile" causes the UDF to calculate when the worksheet
recalculates, but, simply changing the font to bold in a cell doesn't
trigger the recalc. You could change the If loop to coutn or sum
pretty much anything you want.

Good luck.

Ken
Norfolk, Va



GeneR wrote:
Is there a way to count/sum cells by their formatting? For example, could I
count or sum the number of cells that are "Highlighted" or that the text was
"Bold"?





All times are GMT +1. The time now is 02:52 PM.

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