+ Reply to Thread
Results 1 to 7 of 7

VLOOKUP to find values in text string???

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    115

    VLOOKUP to find values in text string???

    I need to to highlight keywords within a block of text (string). I don't need to necessarily return a value with the VLOOKUP. I just need to compare keyword list in Column B to the Text in Cell A1. If the word from the list appears in the text, I need it to be highlighted for every instance.

    EXAMPLE
    Text String (A1)

    Welcome to Jake's Car Accessories website. We have all of your car accessory needs including car covers, truck covers, custom car grills and other car accessories.

    Keyword List (Column B)
    car accessory
    car covers
    truck covers
    car accessories


    I think VLOOKUP only works on lists. I'm not sure if it is possible to do this. Any ideas or alternative suggestions are greatly appreciated.

    Thanks!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VLOOKUP to find values in text string???

    You need code to do this:
    Sub x()
        Dim rA          As Range
        Dim rB          As Range
        Dim cellA       As Range
        Dim cellB       As Range
        Dim sA          As String
        Dim sB          As String
        Dim iPos        As Long
    
        Set rA = Range("A1", Cells(Rows.Count, "A").End(xlUp))
        Set rB = Range("B1", Cells(Rows.Count, "B").End(xlUp))
    
        With rA.Font
            .Bold = False
            .Italic = False
            .Underline = False
            .ColorIndex = xlColorIndexAutomatic
        End With
            
        For Each cellA In rA
            If VarType(cellA.Value) = vbString Then
                sA = UCase(cellA.Value)
    
                For Each cellB In rB
                    If VarType(cellB.Value) = vbString Then
                        sB = UCase(cellB.Value)
                        
                        iPos = 0
                        iPos = InStr(iPos + 1, sA, sB)
                        Do While iPos
                            With cellA.Characters(Start:=iPos, Length:=Len(cellB.Text)).Font
                                .Bold = True
                                .Italic = True
                                .Color = vbRed
                                .Underline = True
                            End With
                            iPos = InStr(iPos + 1, sA, sB)
                        Loop
                    End If
                Next cellB
            End If
        Next cellA
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    lisle il
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: VLOOKUP to find values in text string???

    How do you insert this code into your excel worksheet?

  4. #4
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    115

    Re: VLOOKUP to find values in text string???

    Dude.... you are so freaking awesome! Exactly what I was looking for

  5. #5
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    115

    Re: VLOOKUP to find values in text string???

    Now.... one quick thing.

    Say for instance I have a Column C with hyperlinks. Could this code be modified to dynamically insert hyperlinks based on the keywords from maybe a VLOOKUP?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VLOOKUP to find values in text string???

    That's a completely different question for a completely different thread.

  7. #7
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    115

    Re: VLOOKUP to find values in text string???

    Well.... thanks a lot for your time and help. I really appreciate that

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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