IF? VBA? I don't know? IF statement based on formatting (Underline, Bold, Cell Colour, etc.)

JakeSherlock

New Member
Joined
May 28, 2014
Messages
6
So. We have a file and in that file is a list. and in that list are numbers that are conditionally formatted based on what the number is. And some of those numbers are underlined as the numbers that need to be pulled for counting. I need to total up how many are underlined based on what colour they are.

Example;

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD="align: center"]256[/TD]
[TD="align: center"]246[/TD]
[TD="align: center"]267[/TD]
[/TR]
[TR]
[TD="align: center"]359[/TD]
[TD="align: center"]302[/TD]
[TD="align: center"]354[/TD]
[/TR]
[TR]
[TD="align: center"]225[/TD]
[TD="align: center"]222[/TD]
[TD="align: center"]233[/TD]
[/TR]
[TR]
[TD="align: center"]65[/TD]
[TD="align: center"]54[/TD]
[TD="align: center"]41[/TD]
[/TR]
[TR]
[TD="align: center"]358[/TD]
[TD="align: center"]342[/TD]
[TD="align: center"]328[/TD]
[/TR]
</tbody>[/TABLE]

2 total
2 total
1 total

Now I thought that maybe I could use IF, but I am unaware of what IF statement may be used for formatting based IFs.? If IF is the right IF? If we are going to use VBS, I'm a noob and may not understand lingo.

Thanks for help in advance.

-Jake
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Formulas cannot detect format, so in that sense you would need to use VBA. However....you mention that these cells are conditionally formatted. Are the underlines a result of conditional formatting or are those done manually?
 
Upvote 0
Underline is manual. Colour is auto (Conditional).

-J

OK, then you'll need to use VBA. This assumes your data is in A1:C5. You can change the highlighted range to your actual range.

Code:
Sub CountUnderline()

    Dim s As Range
    Dim Aqua As Long
    Dim Blue As Long
    Dim Pink As Long
    
    For Each s In Range("[B][COLOR=#ff0000]A1:C5[/COLOR][/B]").Cells
        If s.Font.ColorIndex = 8 And s.Font.Underline = xlUnderlineStyleSingle Then
            Aqua = Aqua + 1
        ElseIf s.Font.ColorIndex = 5 And s.Font.Underline = xlUnderlineStyleSingle Then
            Blue = Blue + 1
        ElseIf s.Font.ColorIndex = 38 And s.Font.Underline = xlUnderlineStyleSingle Then
            Pink = Pink + 1
        End If
    Next s
    
    MsgBox ("Aqua count = " & Aqua & Chr(10) & "Blue count = " & Blue _
        & Chr(10) & "Pink count = " & Pink)
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,939
Messages
6,175,533
Members
452,652
Latest member
eduedu

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