Hi all,
I've written a UDF to sum up all the bold numbers in a 1-column range. The initial code worked fine, except that if the specified range was an entire column then the computation took some time to process all 65536 rows. I added the condition that only those cells should be processed whose row is less than or equal to the row of the last used cell. For this I added the variable LastRow. Although the formula for computing LastRow works correctly in a Sub procedure, the value returned within the Function, for reasons best known to Mr. Gates, is always 1.
Would appreciate any help with this. My code is reproduced below.
Thanks
m
Code
Function SUMBOLD(rngSumRange As Range) As Variant
'LastRow returns erroneous result in function.
Dim rCell As Range
Dim LastRow As Long
LastRow = rngSumRange.SpecialCells(xlCellTypeLastCell).Row
SUMBOLD = 0
If rngSumRange.Columns.Count > 1 Then SUMBOLD = "NUM!": Exit Function
For Each rCell In rngSumRange
If rCell.Row > LastRow Then Exit Function
If IsNumeric(rCell) And rCell.Font.Bold = True Then
SUMBOLD = SUMBOLD + rCell
End If
Next
End Function
Display More