Looking to Test for Bold, Underline and/or Italic

G

Guest

Is there a function to test for bold, italic or underline?

I am importing a large file of data and want to easily locate these
specially formatted items?
Thanks,
Fred Goldstein
 
F

Frank Kabel

Hi
you'll need VBA for this. e.g. try the following UDF:

'---------------------------------------------------------------------
' TextStyle Function
'---------------------------------------------------------------------
' Function: Returns the textstyle of the supplied range
' Synopsis: Works through each cell in the supplied range and
' determines the text style, and adds to array
' Finishes by returning acumulated array
' Variations: Determines which style to count:
' 1: Underline
' 2: Bold
' 3: Italic
' Constraints: Does not count styles set by conditional formatting
'---------------------------------------------------------------------
' Author: Bob Phillips / Frank Kabel
'---------------------------------------------------------------------

Function TextStyle(rng As Range, _
Optional iStyle As Integer = 1) As Variant
Dim cell As Range, row As Range
Dim i As Long, j As Long
Dim aryStyle As Variant

If rng.Areas.Count > 1 Then
TextStyle = CVErr(xlErrValue)
Exit Function
End If

If rng.Cells.Count = 1 Then
Select Case iStyle
Case 1:
aryStyle = (rng.Font.Underline <> xlUnderlineStyleNone)
Case 2:
aryStyle = rng.Font.Bold
Case 3:
aryStyle = rng.Font.Italic
End Select

Else
aryStyle = rng.Value
i = 0

For Each row In rng.Rows
i = i + 1
j = 0

For Each cell In row.Cells
j = j + 1
Select Case iStyle
Case 1:
aryStyle(i, j) = CBool(cell.Font.Underline
<> xlUnderlineStyleNone)
Case 2:
aryStyle(i, j) = CBool(cell.Font.Bold =
True)
Case 3:
aryStyle(i, j) = CBool(cell.Font.Italic)
End Select
Next cell
Next row
End If

TextStyle = aryStyle

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top