• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to grab underlined text in a cell

iRasim

Member
Hi all,

I want to grab the underlined text in a cell. Is it possible?
for ex; in a1 there are (John (alt+enter) Nick (alt+enter) Rosa. I want to grab Rosa in cell b1.
 
Copy the code below into a code module in VBA
then on the worksheet use:

if B2: Chandoo.org

in another cell use:
=Find_Underline(B2)
=doo


Code:
Function Find_Underline(Rng As Range) As String
  Dim i As Integer
  
  For i = 1 To Len(Rng.Value)
  With Rng
  If .Characters(Start:=i, Length:=1).Font.Underline <> xlUnderlineStyleNone Then
  Underline = Underline & .Characters(i, 1).Caption
  Else
  If Mid(Rng, i, 1) = Chr(32) Then Underline = Underline & Mid(Rng, i, 1)
  End If
  End With
  Next i
  
  Find_Underline = Application.Trim(Underline)
End Function
 
Back
Top