VBA - Macro Search, Highlight and Bold in red Predefined Keywords

gentibr

New Member
Joined
Apr 4, 2016
Messages
3
Hi,

I am looking for a macro (VBA) in Excel 2010 that when applied will search in Column A to find the keywords that are predefined in Column B and those that match will be bold and red color.

For the sake of providing an example below is the expected result when the macro is run:

Description of the Items
Keywords
System Production and MaintenanceSyst
Information and CRM Module Inform
Hardware and Software Business Continuity CenterHardware
Electronic Equipment Electro
Data Center CRM

<tbody>
</tbody>
Thank you in advance for your cooperation!


<tbody>
</tbody>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Rich (BB code):
Sub changeColors()


With Sheets("Sheet2") 'or whatever your sheet name is


Dim keyWord As String, myLoop As Long, keyLoop As Long, myLength As Integer
Dim lastKey As Long, lastRow As Long, testCell As Range, startChar As Integer
    lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    lastKey = .Cells(.Rows.Count, 2).End(xlUp).Row


For myLoop = 2 To lastRow
Set testCell = .Cells(myLoop, 1)


    'test for keywords
    For keyLoop = 2 To lastKey
        keyWord = .Cells(keyLoop, 2).Value
        myLength = Len(keyWord)
        
        If InStr(testCell, keyWord) Then
            startChar = InStr(testCell, keyWord)
            .Cells(myLoop, 1).Characters(startChar, myLength).Font.ColorIndex = 3
        End If
    
    Next keyLoop


Next myLoop


End With
End Sub
 
Last edited:
Upvote 0
Wow that's great man. It really did the gig. One more thing, is it possible to also have it in bold.

Thanks a bunch!
 
Upvote 0
Yeah just add it in right here:

Code:
         If InStr(testCell, keyWord) Then
            startChar = InStr(testCell, keyWord)
            .Cells(myLoop, 1).Characters(startChar, myLength).Font.ColorIndex = 3
            .Cells(myLoop, 1).Characters(startChar, myLength).Font.Bold = True
        End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,914
Members
449,132
Latest member
Rosie14

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