+ Reply to Thread
Results 1 to 8 of 8

Find text and highlight in Excel cell

  1. #1
    Registered User
    Join Date
    10-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    8

    Find text and highlight in Excel cell

    Hello all,

    Suppose I have "abc" in A1, "def" in A2, "ghijk" in A3 and "lmn" in A4. I want to test a text string in A6 to see 1) the text string has any of A1/A2 and highlight as yellow; 2) test if the text has any of A3 and A4 and highlight as green. Let's say I have a text string in A6 like this, "abcghiabcdefghijkabcdeflmnabclmnlmn". Could someone help me with a macro?

    Thanks,

    MC

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Find text and highlight in Excel cell

    You don't need a macro for this, you can do it with conditional formatting. See attached example. What do you want to do if it has a match for both?
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Find text and highlight in Excel cell

    i think op wants it like this
    abcghiabcdefghijkabcdeflmnabclmnlmn
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Find text and highlight in Excel cell

    Oh, good insight. I need to spend more time in the pub

    Here is code that will do that:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Find text and highlight in Excel cell

    Thanks all for the response. It didn't go through at my hand...when debugging it said "unable to get the Characters property of the Range class" at the line "RefCell.Characters(Start:=Found, Length:=Len(CellToMatch)).Font.Color = ColorValue".
    Any insight?

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Find text and highlight in Excel cell

    I tested this code in a sheet using your example data and it worked, see attached and compare yours to this. If you're having problems with the exact same code then it might help to attach the actual file you're working with. It is possible that there is a boundary condition with your data that the logic does not deal with properly.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-02-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Find text and highlight in Excel cell

    I copied the one you attached and it worked very well. You are the man...

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Find text and highlight in Excel cell

    Glad to help! If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved.

    Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

+ 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. Macro to find text and highlight row
    By Shruikan in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-05-2019, 08:58 AM
  2. Find and highlight words from two tables of text
    By ineedthisspread in forum Excel General
    Replies: 1
    Last Post: 12-23-2012, 01:47 AM
  3. [SOLVED] Code to find text in a worksheet and highlight it
    By NYEng2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2012, 11:16 AM
  4. Find and highlight/bold/underline/colour a block of matching text (is this possible?)
    By joelhuang in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-02-2011, 07:44 AM
  5. VBA to find and select text within text and highlight
    By Marrick13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2011, 08:05 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