View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Brainless_in_Boston
 
Posts: n/a
Default count BOLD text cells? ANSWER!?!!!

Check out this cool link found after 2 google searches:

http://www.mcgimpsey.com/excel/udfs/sumbold.html

Here's their answer with code, I have not tested it:


One problem is that there are no events that fire when cell formatting is
changed. While using Application.Volatile causes the cell to recalculate any
time a calculation is done on the worksheet, this means that the cell may not
contain a valid value unless a manual calculation (e.g., F9) is performed.

Put this in a regular code module.

'************************************************* *****
'Purpose: Sum cells with bold formatting applied
'Inputs: vInput - array of one or more input ranges
'Returns: Sum of cells in vInput with bold formatting
'************************************************* *****
Public Function SumBold( _
ParamArray vInput() As Variant) As Variant
Dim rParam As Variant
Dim rCell As Range
Dim vTemp As Variant

Application.Volatile
On Error GoTo ErrHandler
For Each rParam In vInput
If TypeName(rParam) = "Range" Then
With rParam
For Each rCell In Intersect( _
.Cells, .Cells.Parent.UsedRange)
With rCell
If .Font.Bold Then
If IsError(.Value) Then
vTemp = .Value
Exit For
ElseIf VarType(.Value2) = vbDouble Then
vTemp = vTemp + .Value2
End If
End If
End With
Next rCell
End With
End If
Next rParam
SumBold = vTemp
Continue:
On Error GoTo 0
Exit Function
ErrHandler: 'Check for overflow
If Err.Number = 6 Then SumBold = CVErr(xlErrNum)
Resume Continue
End Function

Thanks to Harlan Grove for pointing out that the .Value2 property was
appropriate to use here, rather than .Value.

=====================

Pretty cool, eh? Anyone want to test this & post results? I don'thave time
right now...

Mark aka Brainless in Boston


"Sandy" wrote:

Sorry Misposted as reply to your post