automatically underline certain key words in all cells in a column

skyport

Active Member
Joined
Aug 3, 2014
Messages
374
Was hoping there is a chance this can actually be done with some sort of VBA -automatically underline certain key words in all cells in a column
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
skyport,

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


1. Can we have a screenshot of the list of key words?

2. Can we have a screenshot of the cells in a column containing the words/strings to underline?


To post a small screen shot try one of the following:

Excel Jeanie
Download

MrExcel HTML Maker
https://onedrive.live.com/?cid=8cffdec0ce27e813&sc=documents&id=8CFFDEC0CE27E813!189

Borders-Copy-Paste
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

To test the above:
Test Here


Or, you can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
for instance, your keywords is x and the column you want to apply is A
Code:
sub t
dim a as range
for each a in columns(1)
if a.value="x" then
a.Font.Underline = xlUnderlineStyleSingle
end if
next
end sub

if you have more than one keyword. you can use
Code:
if a.value="x" or a.value="y" or a.value="z" then
 
Last edited:
Upvote 0
Thanks for helping me. I tried the formula as follows considering the data is in column K:
Sub t()
Dim a As Range
For Each a In Columns(K)
If a.Value = "anxiety" Or a.Value = "depression" Or a.Value = "psychiatric" Then
a.Font.Underline = xlUnderlineStyleSingle
End If
Next
End Sub

Received a runtime error 1004 application-defined or object-defined error
 
Upvote 0
also, if I specify the column as (11) instead of K, I get - runtime error 13 type mismatch
 
Upvote 0
Hiker, nice to see you here again. You solved a problem for me a while back.

Windows 7 Excel 2000
using a PC
key words would be ipdated on an ongoing basis
 
Upvote 0
Please use code tags. ([ code] at the beginning and [ /code] at the end. Both without the spaces.

Another way of doing it.
Code:
Sub Maybe()
    Dim c As Range
    For Each c In Range("K2:K" & Cells(Rows.Count, 11).End(xlUp).Row)
        Select Case c.Value
        Case "anxiety"
            c.Font.Underline = xlUnderlineStyleSingle
        Case "depression"
            c.Font.Underline = xlUnderlineStyleSingle
        Case "psychiatric"
            c.Font.Underline = xlUnderlineStyleSingle
        Case Else
        End Select
    Next c
End Sub

Or shorter maybe

Code:
Sub Maybe()
    Dim c As Range
    For Each c In Range("K2:K" & Cells(Rows.Count, 11).End(xlUp).Row)
        Select Case c.Value
        Case "anxiety", "depression", "psychiatric"
            c.Font.Underline = xlUnderlineStyleSingle
        End Select
    Next c
End Sub
 
Last edited:
Upvote 0
try
for each a in range(cells(1,11),cells(rows.count,11))
 
Last edited:
Upvote 0
Have tried all the solutions presented so far and it does not seem to want to underline anything. I tried it on different pages as well just to be sure.
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top