VBA - Macro Search, Highlight Red and Bold Predefined Keywords

gittymoe

Board Regular
Joined
Apr 23, 2005
Messages
79
I am looking for a macro (VBA) in Excel 2016 that when applied will search for the predefined keywords in Workbook "Keywords" Column A against Workbook "Voice" Column K to find the predefined keywords in Workbook "Keywords" Column A and those that match will be bold and red color. Sorry guys I could not figure out how to show the bold and Red color but if you could imagine in column B below the keywords ONLY from A would be Red & Bold (i.e. broke, chopped, slash).

Example below is the expected result when the macro is run:

Book1
AB
1KeywordsReview
2brokenI broke this just a few days ago and I really like it.
3brokeThis is now broken
4choppedThis chopped the wood great
5slashWe were able to slash prices
Sheet1
<p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color:
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Ok, try this.
Workbook "Voice" must be active.
You may change the sheet name to suit.

Code:
[COLOR=blue]Sub[/COLOR] a1017209a[B]()[/B]
[COLOR=blue]Dim[/COLOR] va
[COLOR=blue]Dim[/COLOR] i [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR][B],[/B] x [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR]
[COLOR=blue]
With[/COLOR] Workbooks[B]([/B][COLOR=brown]"Keywords"[/COLOR][B]).[/B]Sheets[B]([/B][COLOR=brown]"sheet1"[/COLOR][B])[/B]
va [B]=[/B] [B].[/B]Range[B]([/B][COLOR=brown]"A1"[/COLOR][B],[/B] [B].[/B]Cells[B]([/B]Rows.count[B],[/B] [COLOR=brown]"A"[/COLOR][B]).[/B][COLOR=blue]End[/COLOR][B]([/B]xlUp[B]))[/B]
[COLOR=blue]End[/COLOR] [COLOR=blue]With[/COLOR]
 
[COLOR=blue]For[/COLOR] i [B]=[/B] [B][COLOR=crimson]2[/COLOR][/B] [COLOR=blue]To[/COLOR] UBound[B]([/B]va[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B])[/B]
   [COLOR=blue]With[/COLOR] Cells[B]([/B]i[B],[/B] [COLOR=brown]"K"[/COLOR][B])[/B]
      [COLOR=blue]If[/COLOR] InStr[B]([/B][B][COLOR=crimson]1[/COLOR][/B][B],[/B] [B].[/B]Value[B],[/B] va[B]([/B]i[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B]),[/B] vbTextCompare[B])[/B] [COLOR=blue]Then[/COLOR]
         x [B]=[/B] InStr[B]([/B][B][COLOR=crimson]1[/COLOR][/B][B],[/B] [B].[/B]Value[B],[/B] va[B]([/B]i[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B]),[/B] vbTextCompare[B])[/B]
         [B].[/B]Characters[B]([/B]x[B],[/B] Len[B]([/B]va[B]([/B]i[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B]))).[/B]Font.Color [B]=[/B] vbRed
         [B].[/B]Characters[B]([/B]x[B],[/B] Len[B]([/B]va[B]([/B]i[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B]))).[/B]Font.Bold [B]=[/B] [COLOR=blue]True[/COLOR]
      [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
   [COLOR=blue]End[/COLOR] [COLOR=blue]With[/COLOR]
[COLOR=blue]Next[/COLOR]
 
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
 
Last edited:
Upvote 0
Akuni, Thanks I have plugged this into my module but I am not getting the desired results. It seems to find the word broke on the first row in column K but nothing else. I am sure I am not doing something right any insight?

Judd
 
Upvote 0
I assumed this:
The keywords are in Workbooks("Keywords") col A. The data is in Workbook "Voice" Column K.
Is that correct?

Did you change this part to suit: Workbooks("Keywords").Sheets("sheet1")?
The result in col K:

Review
I broke this just a few days ago and I really like it.
This is now broken
This chopped the wood great
We were able to slash prices

(Sorry, I can't post a table with colored font.)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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