One way:
Option Explicit
Sub testme()
Dim myVal As Long
myVal = FindUnderline(Range("a1"))
If myVal = 0 Then
MsgBox "no characters underlined"
Else
MsgBox "first underline at: " & myVal
End If
End Sub
Function FindUnderline(ByVal myCell As Range) As Long
Dim l_Position As Integer
FindUnderline = 0
For l_Position = 1 To Len(myCell.Value)
If myCell.Characters(Start:=l_Position, Length:=1).Font.Underline _
= xlUnderlineStyleNone Then
'keep looking
Else
FindUnderline = l_Position
Exit Function
End If
Next l_Position
End Function
If you look at VBA's help, you'll see:
XlUnderlineStyle can be one of these XlUnderlineStyle constants.
xlUnderlineStyleNone
xlUnderlineStyleSingle
xlUnderlineStyleDouble
xlUnderlineStyleSingleAccounting
xlUnderlineStyleDoubleAccounting
(if you wanted to look for a particular style)
jquiet wrote:
I have several characters in a cell, for example "7432". I chose text format
so that I could underline one of the characters, for example the "3". How do
I find out programmatically that the 3 is the character that is underlined?
Assume that the value is in Cells(2,1). I know a loop is involved and I
don't have too much trouble programming but I don't see something that will
tell me the format of a specific character.
Here's some code I started:
Function FindUnderline(ByVal MyNumber)
Dim l_length As Integer
l_length = Len(Cells(2, 1))
Dim l_Position As Integer
Dim l_String As String
For l_Position = 1 To l_length
l_String = Mid(Cells(2, 1), l_Position, 1)
Next l_Position
End Function
Thanks for you help
--
Dave Peterson