+ Reply to Thread
Results 1 to 4 of 4

VBA to Highlight Rows that Contain Any Keywords in Lookup Table

  1. #1
    Registered User
    Join Date
    02-10-2010
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2002
    Posts
    28

    Question VBA to Highlight Rows that Contain Any Keywords in Lookup Table

    Hi all,

    I've scoured the internet for a solution and have tried coming up with a solution myself, but I'm just not proficient enough with VBA to be able to do it (and all of the solutions that I could find online involved a popup input box to manually enter keywords each time).

    I'm trying to get a macro to look for any and all keywords in a table named "KeywordLookupTable" on another worksheet and if any of those words are contained in a column called "Name" in the current active table, it highlights the cell that contains it (or the entire row that contains it). The keywords should not be case sensitive and the list will be dynamic in the sense that I will change, add and delete keywords to be able to use in different data sets.

    I don't want to use conditional formatting, as I would need to constantly recreate the rules for other files/data sets, and the file size would be a lot bigger as some of the data sets I use are huge.

    I have sample data, keywords and output (only a portion of the original dataset) in the attached spreadsheet...if anyone is able to help me figure this out, I would be extremely appreciative!

    Thank you in advance!

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this !


    According to your attachment a VBA demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
                
    Dim WRf As RangeR&
        
    With Sheet1.ListObjects(1).DataBodyRange.Columns(3)
                   .
    Interior.ColorIndex xlNone
            
    For Each W In Sheet2.ListObjects(1).DataBodyRange.Value
                   Set Rf 
    = .Find(W, , xlValues2)
                If 
    Not Rf Is Nothing Then
                           R 
    Rf.Row
                    
    Do
                               
    Rf.Interior.ColorIndex 37 + (Rf(0).Interior.ColorIndex 37)
                           
    Set Rf = .FindNext(Rf)
                    
    Loop Until Rf.Row R
                End 
    If
            
    Next
        End With
                   Set Rf 
    Nothing
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Registered User
    Join Date
    02-10-2010
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2002
    Posts
    28

    Re: Hi, try this !

    Hey Marc! Thank you for being the only one on this as well as another forum to reply with a solution!

    It looks like your solution is working after a couple of tweaks to the table references, but do you know why the cells are being colored two different colors (pale blue and pale yellow) rather than just one color? If I comment the second part out (+ (Rf(0).Interior.ColorIndex = 37)) it highlights the cells with only the one color, but I don't know what that code is meant to do besides change the color.
    Last edited by seaottr; 01-24-2023 at 11:16 AM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA to Highlight Rows that Contain Any Keywords in Lookup Table


    Wild Cross Posting ‼

    If I knew this I did not post anything … Whatever the Excel forum you must read forum rules !

    Anyway I should have written « an Excel basics UKV layout VBA demonstration » …
    But as a beginner starter you could / should easily mod it as per your will …

    Thanks for the rep' !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to highlight rows in Tab 1 with matching keywords from Tab 2?
    By eyah002 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-17-2020, 01:11 PM
  2. How to highlight certain keywords that I search.
    By ExcelNewbie1994 in forum Excel - New Users/Basics
    Replies: 26
    Last Post: 02-26-2020, 03:48 PM
  3. Highlight certain keywords and delete entire column.
    By ExcelNewbie1994 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2020, 04:04 PM
  4. How to Highlight or Remove Based on Many Keywords
    By NYCData in forum Excel General
    Replies: 2
    Last Post: 10-19-2017, 05:25 AM
  5. VBA Code to search keywords, then highlight when found
    By koz81 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2014, 05:52 PM
  6. [SOLVED] Search for keywords and copy rows containing keywords to new sheet
    By lenorsk in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-15-2013, 06:54 AM
  7. [SOLVED] Macro to highlight keywords-Macrobutton not working fine
    By Awalgaonkar in forum Word Formatting & General
    Replies: 2
    Last Post: 03-27-2013, 08:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1