There's no such thing as a stupid question, but they're the easiest to answer.


Search Search
Search for:
Tech Support Guy > > >

Excel 2007 macro - locate specific word & underline it


Brad3's Avatar
Brad3 Brad3 is offline
Computer Specs
Junior Member with 1 posts.
Join Date: Jun 2011
Experience: Intermediate
15-Jun-2011, 04:10 PM #1
Excel 2007 macro - locate specific word & underline it
How do you make a macro that does the following:
  1. go to next cell down in Column D
  2. copy contents (a single word) of that cell
  3. select entire Column A
  4. find first instance, in Column A, of the word that was copied from Column D, above, (the word is part of a sentence in a single cell in Column A),
  5. underline just that word (not the whole sentence) in Column A
  6. loop
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,936 posts.
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
21-Jun-2011, 06:25 AM #2
Hi Brad, welcome to the forum

I just recorded a amcro that does that and translated it to vba code

Function ULinetxt(cVal As String, uStr As String)
Dim tp1 As Integer, tp2 As Integer
If InStr(1, LCase(cVal), LCase(uStr)) > 0 Then
    tp1 = InStr(1, cVal, uStr)
    tp2 = Len(uStr)
    With ActiveCell.Characters(Start:=tp1, Length:=tp2).Font
        .Underline = xlUnderlineStyleSingle
    End With
End If
End Function
Sub test()
    Call ULinetxt(ActiveCell.Value, "underline")
End Sub
You could use this function in vba macro and it's done

Select a cell with your data string and rin the test macro, replace the word "underline" with the text you want underlined and the first occurrence (if found) will be underlined, case is not matched.

Let me know it it works for you.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

2007, excel, find, macro, underline

Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

You Are Using: Server ID
Trusted Website Back to the Top ↑