+ Reply to Thread
Results 1 to 15 of 15

Search for exact match of string and highlight

  1. #1
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Search for exact match of string and highlight

    Hello All,
    I am looking for a VBA code to help me find an exact string in a text and highlight it:
    Example: I have following text in a cell and I am looking e.g. for the exact word "seed", and not "seedling". How can I find it and highlight it?

    "Seed under water stress: Twenty-four T1 seed from each event (a selfed TO parent) were germinated. Taqman analysis was used to establish zygosity in each seedling. Homozygotes were set aside for seedbulking. Hemizygotes and azygotes were analyzed using the greenhouse water stress protocol. The promoter is also expressed in seed."


    Your help is highly appreciated!

    Niclal

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

    Lightbulb Re: Search for exact match of string and highlight


    Hi,

    See help of VBA Find method …

    You can also activate Macro Recorder and use the Find function from the worksheet menu : you'll get a free code !

  3. #3
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    Hello Marc,
    This will only find a partial match in Excel . I need an exact match.
    Thanks
    N

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

    Re: Search for exact match of string and highlight


    Nope ! Can an exact match if you well fill it …

  5. #5
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    I have used the Find/Replace in Excel and the whole cell is highlighted in red.
    So, I would appreciate if you could guide me.
    N

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

    Re: Search for exact match of string and highlight


    Attach a sample file in xlsx format and post your initial code between tags.

  7. #7
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    Hi,
    I have aatached a sample.
    I don't have a code
    Thank you
    book.xlsx

  8. #8
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    Hi,
    I have recorded a macro; however, all words are highlighted red.
    N

    Please Login or Register  to view this content.

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

    Cool Try this demonstration !


    Working like a breeze on my side !

    Please Login or Register  to view this content.
    Do you like ? Thanks to click on bottom left star « Add Reputation » !
    Last edited by Marc L; 10-10-2014 at 08:09 AM.

  10. #10
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    Hi Marc,
    Hurray! You did it.
    Could I please ask you a favor: Could you explain a bit the different steps so that I can learn. I am still a newbie. Thanks a bunch!
    N

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

    Post Re: Search for exact match of string and highlight


    Specials explanations in VBA inner help : select an instruction in the code and hit F1 key and just read !

    CH constant is the list of allowed characters in next character after the word.

    The procedure searches a word (WD constant) in current block from A1 cell.
    When the word is found in a cell, it checks each instance by comparing next character with CH constant …
    Last edited by Marc L; 10-11-2014 at 05:25 AM.

  12. #12
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    Hi Marc,
    I am coming regarding one issue: if I search "seed", the word "oilseed" should not be highlighted. What sould be changed in the your code?
    Much appreciated!
    N

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

    Re: Search for exact match of string and highlight


    Please Login or Register  to view this content.
    Last edited by Marc L; 10-15-2014 at 10:26 AM. Reason: sorry, optimization …

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

    Re: Search for exact match of string and highlight


    See last edit of previous post …

  15. #15
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Search for exact match of string and highlight

    Thank yoouuuuuuu!
    N

+ 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] Possible to search for a substring withing a string of text which is an exact match?
    By Urugmo88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-07-2014, 04:09 AM
  2. Search and Remove Exact String
    By Beaster in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-04-2013, 02:28 PM
  3. Replies: 6
    Last Post: 01-28-2012, 06:59 PM
  4. Replies: 2
    Last Post: 01-28-2012, 05:26 PM
  5. Search for EXACT string
    By jarochnrol in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2011, 11:39 AM

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