+ Reply to Thread
Results 1 to 6 of 6

Macro that searches for a various strings in an Excel column, help

  1. #1
    Registered User
    Join Date
    07-08-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro that searches for a various strings in an Excel column, help

    Hi all,

    I found a macro that searches for a particular string in an Excel column and highlights the rows where that string appears.

    I actually would like to search for multiple strings, around 200 or so instead of only looking for one. I'm assuming I'd need to create an array to do this but I'm not sure how to go about this.. or is there some built in function I can use?

    Here is the macro:

    Please Login or Register  to view this content.
    Any help would be apprecieated.
    Last edited by ivopld; 07-08-2009 at 05:18 PM. Reason: asked by moderator

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

    Re: Need some help with a macro

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then amend your thread title accordingly and change the QUOTE tags to CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro that searches for a various strings in an Excel column, help

    hi,

    Tusha Mehta provides an alternative approach in identifying the range, by building it as a range rather than as an address string, in this link: http://www.tushar-mehta.com/excel/tips/findall.html

    I have modified your code to use Tusha's function & loop through all the strings you need to find (using a list in column A on a new sheet - see macro). I suggest that you rename your variables for greater clarity. The below is untested but should point you in the general direction...

    Please Login or Register  to view this content.
    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  4. #4
    Registered User
    Join Date
    07-08-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro that searches for a various strings in an Excel column, help

    Thanks Rob, but I'm having some issues with the code. When I create the macro I get a compiler error 'Sub or Function not defined' for the FindAll function. Should I be declaring this somewhere?

    Also, I'm not quite sure where to specify the strings that I'd be looking for. For example, if I want to search for the strings Jack, Stacy, and Susan where would I specify them exactly?

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

    Re: Macro that searches for a various strings in an Excel column, help

    You'd find the code for FindAll at the link Rob posted.

  6. #6
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro that searches for a various strings in an Excel column, help



    ivopld,
    Ooopps, sorry about that!
    The below section of code builds the list of strings to search for. To make it work you need to create a sheet in your file called "List of Search Strings" & then list Jack, Stacy, and Susan in cells A1:A3 of the new sheet. I consider that this approach has the advantages of; visibility within your file (no need to view the macro code), easy to update in the file & flexible due to the use of LastRow resulting in no need to change the macro when the list size changes (provided there are no blank cells in the list).

    Please Login or Register  to view this content.
    Shg, Thanks for the correction/pointing the OP in the right direction :-)

    hth
    Rob

+ 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