Consulting

Results 1 to 5 of 5

Thread: Looking to Highlight Certain Phrases

  1. #1

    Looking to Highlight Certain Phrases

    Hello,

    I've ran into a situation where I'm trying to highlight all instances for "pizza deal" the problem is that with the symbols in the word it doesn't highlight all the words such as "pizza deals, online pizza deals, etc." My goal is as long as it has the words "pizza" and "deal" it should highlight that particular cell. I thought maybe using vba could do the trick, but I ran into a dead end again.

    Another option I was thinking about (that I created on the second tab) is having a list of the words I'm looking for such "pizza deal", "salad deal" and it would highlight all those instances including "online salad deals", "deals for pizza" etc. Any help on this would be appreciated...

    Thanks
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    perhaps something like this (for Sheet1)

    PHP Code:
    =IFERROR(FIND("pizza deal",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2,"[",""),"]",""),"+",""))>0,FALSE
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    or:
    =ISNUMBER(SEARCH("pizza",B2)+SEARCH("deal",B2))
    (in column C of Sheet1 of the attached)
    or:
    =ISNUMBER(SUMPRODUCT(SEARCH({"pizza","deal"},B2)))
    (in column D of Sheet1 of the attached)
    On Sheet1 of the attached I've used a variant of the second of these to conditionally format column B:
    =ISNUMBER(SUMPRODUCT(SEARCH($H$2:$I$2,$B2)))

    Here I've referred to cells H2:I2 (highlighted in green on the sheet). Change the values in these cells and the formatting changes in column B.

    On sheet Option two is a vba offering. You're meant to highlight the cells with the phrases (I2:I3), then click the button.
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I'm not 100% sure on the requirement, but using VBA and Option 2 this marks the "Text" cells that have all words from any of the "Lookup" cells




    Option Explicit
    Sub MarkCells()
        Dim ws As Worksheet
        Dim rText As Range, rLookup As Range
        Dim aText() As Variant, aLookup() As Variant
        Dim iLookup As Long, iText As Long, iLookupPiece As Long
        
        Set ws = Worksheets("Option Two")
        Set rText = Range(ws.Cells(1, 1), ws.Cells(1, 1).End(xlDown))
        Set rLookup = Range(ws.Cells(1, 2), ws.Cells(1, 2).End(xlDown))
        
        aText = Application.WorksheetFunction.Transpose(rText)
        
        ReDim aLookup(1 To rLookup.Rows.Count)
        For iLookup = 1 To rLookup.Rows.Count
            aLookup(iLookup) = Split(rLookup.Cells(iLookup, 1).Value, " ")
        Next iLookup
        
        
        For iLookup = LBound(aLookup) + 1 To UBound(aLookup)
            For iText = LBound(aText) + 1 To UBound(aText)
                For iLookupPiece = LBound(aLookup(iLookup)) To UBound(aLookup(iLookup))
                    If InStr(aText(iText), aLookup(iLookup)(iLookupPiece)) = 0 Then Exit For
                    
                    rText.Cells(iText, 1).Interior.Color = vbRed
        
                Next iLookupPiece
        
            Next iText
        Next iLookup
        
        Stop
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Hello,

    I just wanted to thank all those who helped with this problem. The Vba without conditional formatting and the one with conditional formatting both work brilliantly for the objectives.

    Thanks again for looking at this.

Tags for this Thread

Posting Permissions

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