Coding for counting bold / strikethrough / underline / formatted cells ?

rjn008

New Member
Joined
May 12, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Good Morning.

I have the attached and wish to possibly count all or some of the cells that are formatted either by being bold, strikethrough, underlined, italic or coloured text / cell?

Is this possible using similar data to below;

Book2
BC
6Alex Tattersley1Man Utd
7Alex Tattersley2Arsenal
8Ants Farrell (AT)Man Utd
9Ben CummingsBrighton & HA
10Brandon WilkinsonArsenal
11Chris Knutton (AT)Man Utd
12Craig Robbo (G)Brighton & HA
13Daniel CummingsArsenal
14Danny ColbeckArsenal
15Dave CrabtreeNewcastle Utd
16Daz HodgsonMan City
17Dean Barrett1Arsenal
18Dean Barrett2Brighton & HA
19Elliott KenyonBrighton & HA
20Gary CrabtreeBrighton & HA
21Gavin WestNewcastle Utd
22Geordie WatsonMan City
23George Wilkinson (LW)Man Utd
24Glen BroadbentArsenal
25Harvey OakesMan Utd
26Jacob ColcloughMan Utd
27James PinderArsenal
28Jamie BallesterArsenal
29Joe McAdamTottenham
30Joe Slingsby (AT)Brighton & HA
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:C30Expression=ROW(B2)=CurrentRowtextNO
Cells with Data Validation
CellAllowCriteria
C28:C30List=$E$76:$E$96
C26List=$E$76:$E$96
C22:C24List=$E$76:$E$96
C6:C8List=$E$76:$E$96
C11:C12List=$E$76:$E$96
C17:C20List=$E$76:$E$96
C14:C15List=$E$76:$E$96
 
Hi @MARK858 I have got a button now and it is working as I like, could you advise the logic to be added if I was to format 'Italic' and 'Underline'?
If it is a single underline then try...

VBA Code:
Sub countBoldStrk()
    Dim myCell As Range
    Dim myBold As Long, myStrk As Long
    Dim myItal As Long, myUnder As Long
    
    myBold = 0
    myStrk = 0
    myItal = 0
    myUnder = 0
    
    For Each myCell In Range("D5:D29")
        If myCell.Font.Bold Then myBold = myBold + 1
        If myCell.Font.Strikethrough Then myStrk = myStrk + 1
        If myCell.Font.Italic Then myItal = myItal + 1
        If myCell.Font.Underline = xlUnderlineStyleSingle Then myUnder = myUnder + 1
    Next

    Range("D31") = myBold
    Range("D32") = myStrk
    Range("D33") = myItal
    Range("D34") = myUnder

End Sub
 
Upvote 0
Solution

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
@Jeffrey Mahoney I have managed to work this out now how to run on both the coding above... but when i run the original one you sent it opens VBA nd highlights 'End Sub' as below, do you know why?
No, I don't know why. It works on my end. I even copied the code and ran it again
 
Upvote 0
If it is a single underline then try...

VBA Code:
Sub countBoldStrk()
    Dim myCell As Range
    Dim myBold As Long, myStrk As Long
    Dim myItal As Long, myUnder As Long
   
    myBold = 0
    myStrk = 0
    myItal = 0
    myUnder = 0
   
    For Each myCell In Range("D5:D29")
        If myCell.Font.Bold Then myBold = myBold + 1
        If myCell.Font.Strikethrough Then myStrk = myStrk + 1
        If myCell.Font.Italic Then myItal = myItal + 1
        If myCell.Font.Underline = xlUnderlineStyleSingle Then myUnder = myUnder + 1
    Next

    Range("D31") = myBold
    Range("D32") = myStrk
    Range("D33") = myItal
    Range("D34") = myUnder

End Sub
Thank You @MARK858 - one last one, is it possible to set it so the cell could be 'bold and italic' but to not count them individually but as a dual format? in the same coding?
 
Upvote 0
Try (untested)

VBA Code:
Sub countBoldStrk()
    Dim myCell As Range
    Dim myBold As Long, myStrk As Long
    Dim myItal As Long, myUnder As Long, Mxd As Long
    
    myBold = 0
    myStrk = 0
    myItal = 0
    myUnder = 0
    Mxd = 0
    
    For Each myCell In Range("D5:D29")
        If myCell.Font.Bold And myCell.Font.Italic Then Mxd = Mxd + 1
        If myCell.Font.Bold Then myBold = myBold + 1
        If myCell.Font.Strikethrough Then myStrk = myStrk + 1
        If myCell.Font.Italic Then myItal = myItal + 1
        If myCell.Font.Underline <> -4142 Then myUnder = myUnder + 1
    Next

    Range("D31") = myBold - Mxd
    Range("D32") = myStrk
    Range("D33") = myItal - Mxd
    Range("D34") = myUnder
    Range("D35") = Mxd
End Sub
 
Upvote 0
Try (untested)

VBA Code:
Sub countBoldStrk()
    Dim myCell As Range
    Dim myBold As Long, myStrk As Long
    Dim myItal As Long, myUnder As Long, Mxd As Long
   
    myBold = 0
    myStrk = 0
    myItal = 0
    myUnder = 0
    Mxd = 0
   
    For Each myCell In Range("D5:D29")
        If myCell.Font.Bold And myCell.Font.Italic Then Mxd = Mxd + 1
        If myCell.Font.Bold Then myBold = myBold + 1
        If myCell.Font.Strikethrough Then myStrk = myStrk + 1
        If myCell.Font.Italic Then myItal = myItal + 1
        If myCell.Font.Underline <> -4142 Then myUnder = myUnder + 1
    Next

    Range("D31") = myBold - Mxd
    Range("D32") = myStrk
    Range("D33") = myItal - Mxd
    Range("D34") = myUnder
    Range("D35") = Mxd
End Sub
Good Morning @MARK858 - I am going to test this today, 1 I have completely forgotten is, the count of a basic standard cell with standard font - unformatted, is that possible? rather than doing a sum, as my overall totals can be different in different columns?
 
Upvote 0
a basic standard cell with standard font - unformatted
There is no such thing as standard font and all fonts are formatted.
If you want to test a cell to see if it doesn't have strikethrough, underline etc. then AFAIK you would need to test each condition individually (basically the reverse of what I done in the previous code).
 
Upvote 0

Forum statistics

Threads
1,215,130
Messages
6,123,220
Members
449,091
Latest member
jeremy_bp001

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