'How to Identify Cells by Italic Formatting?

I am putting together a sheet of F1 results over the years.

On Wikipedia the fastest laps are denoted by italicized numbers.

When I copy and paste I want to count all cells in the range that are italicized and between the value of 1 and 10.

Here is what I am currently trying.

Sub COUNIFItalics()
Public Function Count_Italic ("A3:Y3 as Range") As Long
Dim Cel As Range
Application.Volatile
For Each Cel In Rng
    If Cel.Font.Italic = True Then
         Count_Italic = Count_Italic + 1
    End If
Next Cel
End Sub

This is trying to count by italics so any help with the "1 is less than or equal to x is less than or equal to 10" part would be amazing.



Solution 1:[1]

I'm assuming that you want a UDF and use it like a formula.

What you are missing is 2 more Ifs to check if the value is equal or more than 1 and equal or less than 10 (or in this case, I use Select statement instead):

Public Function Count_Italic(inputRng As Range) As Long
    Dim Cel As Range
    Application.Volatile
    For Each Cel In inputRng
        If Cel.Font.Italic = True Then
            Select Case Cel.Value
                Case 1 To 10: Count_Italic = Count_Italic + 1
            End Select
        End If
    Next Cel
End Function

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raymond Wu