Resetting cells that have had bold font in to regular font

sadsfan

Board Regular
Joined
Apr 30, 2003
Messages
217
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a spreadsheet where I want to count a range of cells that have bold text in them, I have done this through a function. However, when someone deletes the value in a cell that has a bold font, the cell still shows the font as being bold and the function still counts it even though it is blank. How can I adapt my function to not count cells with a bold font that are blank, or how do I reset a the font in a cell to regular after the value in it has been deleted? I tried using conditional formatting but that didn't work!

Here is the function code
Code:
Function CountBold(WorkRng As Range)Dim Rng As Range
Dim xCount As Long
For Each Rng In WorkRng
    If Rng.Font.Bold Then
        xCount = xCount + 1
    End If
Next
CountBold = xCount
End Function
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about
Code:
Function CountBold(WorkRng As Range)
Dim Rng As Range
Dim xCount As Long
For Each Rng In WorkRng
    If Rng.Font.Bold And Len(Rng.Value) > 0 Then
        xCount = xCount + 1
    End If
Next
CountBold = xCount
End Function
 
Last edited:
Upvote 0
How about
Code:
Function CountBold(WorkRng As Range)
Dim Rng As Range
Dim xCount As Long
For Each Rng In WorkRng
    If Rng.Font.Bold And Len(Rng.Value) > 0 Then
        xCount = xCount + 1
    End If
Next
CountBold = xCount
End Function

Thanks, that worked a treat!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,380
Members
449,097
Latest member
Jabe

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