sumbold

Stclements1

Board Regular
Joined
Sep 15, 2018
Messages
150
Office Version
  1. 365
Platform
  1. Windows
I found this code on the web and have put this into a module and whilst it works it doesn't update if there is a change in the array being calculated.
For example if I had 18 values of which 9 were bold and came to a value of 780 and then one of those bold values were no longer bold the value wouldn't change. Is there further coding that I can put into the function so it updates automatically. In addition the code rounds up the numbers rather than giving the exact number.
VBA Code:
Function SumBold(WorkRng As Range)
Dim Rng As Range
Dim xSum As Long
For Each Rng In WorkRng
    If Rng.Font.Bold Then
        xSum = xSum + Rng.Value
    End If
Next
SumBold = xSum
End Function
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
This will return the exact number & will run whenever any cell on the sheet re-caclulates
VBA Code:
Function SumBold(WorkRng As Range) As Double
Dim Rng As Range
Dim xSum As Double
Application.Volatile
For Each Rng In WorkRng
    If Rng.Font.Bold Then
        xSum = xSum + Rng.Value
    End If
Next
SumBold = xSum
End Function
There is no way to run the function if the cell format is changed. You could create a SelectionChange event that forces calculation, but that means the sheet will recalculate whenever you select a different cell.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top