Total up boldly formatted cells [Closed]

Report
Posts
7
Registration date
Sunday November 16, 2014
Status
Member
Last seen
August 20, 2015
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Good evening much appreciated volunteers

I am using an Excel 2007 spreadsheet to keep track of costs associated with a holiday.

I have bolded all the expenses which have already been paid and I would be most grateful if some could please assist me in providing a formula or function to total these bolded cells. I have found a VBA code that works, but it does not appear to update as I bold more cells. And as soon as I change any of the data within the cell range, the cell with the sumifbold formula throws out an error: #NAME?

I am not experienced in using VBA code.

Here is the code I used:
Function SumIfBold(MyRange As Range) As Double

Dim cell As Range
For Each cell In MyRange
If cell.Font.Bold = True Then
SumIfBold = SumIfBold + cell
End If
Next cell

End Function

Have I done something wrong? Is there a better way??

Any Suggestions that anyone may offer would be greatly appreciated.

Thank you all in advance

3 replies


Hello,

i'm no good with VBA scripts but i do know how to create a formula to add cells.

click the cell where you want the total.

type SUM=(A1,B2,B3)

This example is the total of cell A1 + B2 + B3

If you need to do a range for example A1 -> A10 you would use SUM=(A1:A10)
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
762
Make is a volatile function


Function SumIfBold(MyRange As Range) As Double
Dim cell As Range

Application.Volatile
For Each cell In MyRange
If cell.Font.Bold = True Then
SumIfBold = SumIfBold + cell
End If
Next cell

End Function
Thanks Rizvisa1

I updated my spreadsheet as you suggested. The function totals up all the bold cells, however, if I update the format any of the data in the range to bold, the results do not change accordingly.

Should it?

Thanks again for your help; I am grateful.

Tanya
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
762
if i write in cell A1
=SumIfBold(B2:G10)

if expect the function to update a1, if i modify any cell in range B2:g10
is this not what is happening ?

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!