+ Reply to Thread
Results 1 to 13 of 13

Search and highlight word in cell

Hybrid View

ShailShin Search and highlight word in... 06-18-2014, 04:39 AM
nathansav Re: Search and highlight word... 06-18-2014, 04:42 AM
diberlee Re: Search and highlight word... 06-18-2014, 04:55 AM
ShailShin Re: Search and highlight word... 06-18-2014, 05:07 AM
diberlee Re: Search and highlight word... 06-18-2014, 06:13 AM
ShailShin Re: Search and highlight word... 06-18-2014, 06:24 AM
JOHN H. DAVIS Re: Search and highlight word... 06-18-2014, 06:25 AM
ShailShin Re: Search and highlight word... 06-18-2014, 06:52 AM
jindon Re: Search and highlight word... 06-18-2014, 07:08 AM
ShailShin Re: Search and highlight word... 06-18-2014, 07:12 AM
jindon Re: Search and highlight word... 06-18-2014, 07:25 AM
ShailShin Re: Search and highlight word... 06-18-2014, 08:18 AM
apo Re: Search and highlight word... 06-18-2014, 10:30 AM
  1. #1
    Registered User
    Join Date
    05-21-2014
    Posts
    16

    Search and highlight word in cell

    Hi All,

    I have one task to do i.e., search the word in column A and highlight the same word in column B
    for example...
    column A contains "TEST": Do-not-use str
    So, find TEST in column B and highlight this word in yellow.

    This needs to be done for each column A cells.

    Can you please provide any sample or references for this?

    Thanks in advance!
    ShailShin

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Search and highlight word in cell

    Why not used conditional based formatting with a formula rule?
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    11-25-2011
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    53

    Re: Search and highlight word in cell

    Conditional formatting is probably best as stated above.

    Does column A always contain a certain word, or a list of words, or is it different every time?

  4. #4
    Registered User
    Join Date
    05-21-2014
    Posts
    16

    Re: Search and highlight word in cell

    conditional based will not work here as column A contains different or same words.

  5. #5
    Registered User
    Join Date
    11-25-2011
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    53

    Re: Search and highlight word in cell

    Can you upload a sample workbook so we can see what sort of data you're working with?

  6. #6
    Registered User
    Join Date
    05-21-2014
    Posts
    16

    Re: Search and highlight word in cell

    please find attached sample data for this.

    Thanks,
    shailshin
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Search and highlight word in cell

    Maybe:

    Sub ShailShin()
    Dim i As Long
    Dim rcell As Range
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    For i = Range("A" & Rows.count).End(3)(1).Row To 2 Step -1
        For Each rcell In Range("B2:B" & Range("B" & Rows.count).End(3)(1).Row)
            If rcell.Text = Range("A" & i).Text Then
                rcell.Interior.ColorIndex = 6
            End If
        Next rcell
    Next i
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    End Sub

  8. #8
    Registered User
    Join Date
    05-21-2014
    Posts
    16

    Re: Search and highlight word in cell

    Hi,

    The column B word does not get highlighted in sample file...
    Column A word "TEST" should get highlighted in column B cell word this is test message for TEST in you file.

    Thanks,
    shailshin

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search and highlight word in cell

    ShailShin

    I can not open your attachment.

    Try upload a sample workbook without zip.

  10. #10
    Registered User
    Join Date
    05-21-2014
    Posts
    16

    Re: Search and highlight word in cell

    Please find attached.

    Thanks,
    ShailShin
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search and highlight word in cell

    Do you want to search the word between the w-quotation mark in Col.B and highlight only such word?
    If not, need to see your desired results.
    Sub test()
        Dim r As Range, c As Range, ff As String, txt As String, m As Object
        Columns("b").Font.ColorIndex = xlAutomatic
        With CreateObject("VBScript.RegExp")
            .Global = True: .IgnoreCase = True
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                .Pattern = """([^""]+)"""
                If .test(r.Value) Then
                    txt = .Execute(r.Value)(0).submatches(0)
                    Set c = Columns("b").Find(txt)
                    If Not c Is Nothing Then
                        ff = c.Address
                        Do
                            .Pattern = "\b" & txt & "\b"
                            For Each m In .Execute(c.Value)
                                c.Characters(m.firstindex + 1, m.Length).Font.ColorIndex = 5
                            Next
                            Set c = Columns("b").FindNext(c)
                        Loop Until c.Address = ff
                    End If
                End If
            Next
        End With
    End Sub

  12. #12
    Registered User
    Join Date
    05-21-2014
    Posts
    16

    Re: Search and highlight word in cell

    Hi,

    Yes! this works as per the requirement.
    Thanks a lot!

  13. #13
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Search and highlight word in cell

    Do you want to search the word between the w-quotation mark in Col.B and highlight only such word
    If it's ONLY the words within the quotation marks in Column A that you want colored in Column B. then maybe this also..

    Sub test()
        Dim i, ii, colst, x
        x = Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row)
        For i = LBound(x) To UBound(x)
            On Error Resume Next
            ii = Split(x(i, 1), Chr(34))(1)
            colst = Application.Find(ii, (x(i, 2)), 1)
            Cells(i, 2).Characters(colst, Len(ii)).Font.ColorIndex = 5
    On Error GoTo 0
        Next i
    End Sub
    Last edited by apo; 06-18-2014 at 10:33 AM.

+ 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. Replies: 2
    Last Post: 01-16-2014, 07:25 PM
  2. Replies: 13
    Last Post: 08-04-2011, 09:41 AM
  3. Replies: 1
    Last Post: 01-25-2011, 10:50 PM
  4. Search word and Place founded word in cell
    By 9813268329 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2010, 07:27 AM
  5. Search a word and highlight
    By karinos57 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2008, 04:48 PM

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