COUNT italics

Sigh

Active Member
Joined
Oct 24, 2007
Messages
371
Is it possible to COUNT based on the font style of a cell? I want to count the number of cells in italics if possible.
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Tim_Excel_

Well-known Member
Joined
Jul 12, 2016
Messages
512
Sure. You can determine whether a certain cell has a specific style with
Code:
If Range("A1").Font.Italic = True Then
You can use this in a loop that goes through your whole range.

Code:
For each cl in Range("A1:D1")
    If cl.Font.Italic = True Then
         i =i+1
    End If
Next cl
Then you could display the counted cells in variable i when the loop is finished

Code:
MsgBox "The number of Italic style cells in the range is " & i
 
Last edited:

Sigh

Active Member
Joined
Oct 24, 2007
Messages
371
Hi, thanks for your response. When I run this I get 'invalid outside procedure', I must be doing something wrong...
 

Phuoc

Board Regular
Joined
Apr 29, 2016
Messages
189
Try:
Code:
Public Function Count_Italic(Rng 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 Function
 

Sigh

Active Member
Joined
Oct 24, 2007
Messages
371
Thanks Phuoc but I get 'Expected End Sub' error. Also where in the code to I type the range? Sorry for the basic question.
 

Tim_Excel_

Well-known Member
Joined
Jul 12, 2016
Messages
512
You must be unfamiliar with VBA. Please look up some literature and familiarise yourself with basic VBA

A sub must always start with Sub NAME ()
and end with End Sub
 

Sigh

Active Member
Joined
Oct 24, 2007
Messages
371
You're right, I am unfamiliar with VBA, trouble is I need a quick solution, I will take a tutorial when I'm less busy.
 

Tim_Excel_

Well-known Member
Joined
Jul 12, 2016
Messages
512
Simply conjoin the last two of my scripts into a single sub.
Other than that, Phuoc's function works the same and can be used as a formula in your worksheet.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,099,114
Messages
5,466,760
Members
406,497
Latest member
Bryanlim

This Week's Hot Topics

Top