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
 
Hi Peter,

thanks for the previous help, but lets say I would want to make the specific words in capital letters instead of underline. How would I need to modify the macro to do this?
I've been away for quite a while, but if you are still looking, see if this does what you want.

Code:
Sub CapitaliseKeyWords()
  Dim AllMatches As Object
  Dim itm As Variant
  Dim Cell As Range
  Dim lr As Long
  Dim s As String

  Const myCols As String = "G:I"
  
  Application.ScreenUpdating = False
  lr = Columns(myCols).Find(What:="*", After:=Columns(myCols).Cells(1), LookIn:=xlValues, SearchDirection:=xlPrevious).Row
  With CreateObject("VBScript.RegExp")
    .Global = True
    .IgnoreCase = True
    .Pattern = "\b(" & Join(Application.Transpose(Sheets("Words").Range("A1", Sheets("Words").Cells(Rows.Count, "A").End(xlUp)).Value), "|") & ")\b"
    For Each Cell In Columns(myCols).Resize(lr).Cells
        s = LCase(Cell.Value)
        Set AllMatches = .Execute(s)
        For Each itm In AllMatches
          s = Left(s, itm.firstindex) & UCase(itm) & Mid(s, itm.firstindex + itm.Length + 1)
        Next itm
        Cell.Value = s
    Next Cell
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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