I was asked if there is any way to count all of the bold cells in a range. Of course there is. Here is a simple VBA function that carries out this task:
Function CountBoldCellsInRange(rng As Range) As Long Dim rCell As Range Dim iBold As Long iBold = 0 For Each rCell In rng If rCell.Font.Bold Then iBold = iBold + 1 End If Next CountBoldCellsInRange = iBold End Function
This function can be called in a number of ways. Here are two examples showing how to call the function from other VBA procedures.
Sub Test1CountBoldCellsInRange() Dim i As Long If TypeName(Selection) = "Range" Then i = CountBoldCellsInRange(Selection) MsgBox "There are " & i & " bold cells in the selected range." Else MsgBox "The selected object is not a range." End If End Sub
Sub Test2CountBoldCellsInRange() Dim i As Long Dim r As Range Dim sAddress As String sAddress = "A1:F20" Set r = ActiveSheet.Range(sAddress) i = CountBoldCellsInRange(r) MsgBox "There are " & i & " bold cells in " & sAddress & "." End Sub
You can even call it from a worksheet cell, using this syntax.