RealityCheque
Technical User
I'm trying to write a function that will count the number of cells within a range that are bold, despite having a function that counts cells of a particular colour I have not managed to adapt it for 'bold checking'.
The colour function that works fine:
The bold function that reports a #name? error:
Can anyone see where I'm going wrong? I must have stared at this for hours trying to spot my mistake
Simon
"I do not have to forgive my enemies. I have had them all shot."
- Ramon Maria Narvaez
The colour function that works fine:
Code:
Function CountByColor(sCountRange As String, Color As Integer) As Long
Dim ColorCount As Long
Dim CountRange As Range
Dim c As cell
Application.Volatile True
Set CountRange = Range(sCountRange)
For Each c In CountRange
If c.Interior.ColorIndex = Color Then
ColorCount = ColorCount + 1
End If
Next
CountByColor = ColorCount
End Function
The bold function that reports a #name? error:
Code:
Function CountByBold(sCountRange As String) As Long
Dim BoldCount As Long
Dim CountRange As Range
Dim c As cell
Application.Volatile True
Set CountRange = Range(sCountRange)
For Each c In CountRange
If c.Font.Bold = True Then
BoldCount = BoldCount + 1
End If
Next
CountByBold = BoldCount
End Function
Can anyone see where I'm going wrong? I must have stared at this for hours trying to spot my mistake
Simon
"I do not have to forgive my enemies. I have had them all shot."
- Ramon Maria Narvaez