Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Finding an underlined character among several characters in a cell

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Finding an underlined character among several characters in a cell

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Finding an underlined character among several characters in acell

Try this one:

Sub ExtractUnderlined()
Dim sUnder As String
Dim i As Integer
Dim n As Integer

n = Len(ActiveCell.Text)

If n 0 Then
For i = 1 To n
If ActiveCell.Characters(i, 1).Font.Underline _
< xlUnderlineStyleNone Then
sUnder = sUnder & ActiveCell.Characters(i, 1).Text
End If
Next
End If

If Len(sUnder) 0 Then
MsgBox "Characters " & sUnder & " in the active cell are underlined", _
vbInformation, "Underlined Characters"
End If

End Sub

You can't just examine the string, because that's just the text. You need to examine
the characters in the cell.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting # of characters before a certain character NickPro72 Excel Discussion (Misc queries) 4 August 22nd 08 09:17 PM
Finding/counting a given character within a cell Bob Excel Worksheet Functions 10 June 7th 06 12:06 AM
Finding a character type within a cell shineboxnj Excel Worksheet Functions 1 July 22nd 05 03:12 AM
inserting a character amongst characters in a cell. philster Excel Programming 3 December 17th 03 02:46 AM
Finding the first few characters in a cell Ben E Excel Programming 1 July 23rd 03 06:20 PM


All times are GMT +1. The time now is 11:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"