+ Reply to Thread
Results 1 to 10 of 10

Searching a range

  1. #1
    Registered User
    Join Date
    01-11-2011
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    41

    Searching a range

    Does anyone have any advise on searching a range (Worksheet Column) for all instances of a particular string ?
    Using VBA
    Thanks.

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

    Re: Searching a range

    I would use the Find method of the range, in a loop.

    But what form do you want your results to take? Do you want a list on a worksheet? A message box? Highlight the instances?

    More detailed questions get more detailed answers.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    01-11-2011
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Searching a range

    Hi Jeff. the results are destined for a listview control. It's getting them I'm looking for. If a loop is the answer I could use a For Next on each row and if the value matches
    add that to the listview. But what is the best method for looping? Set a Range first or can you use a Select query?

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

    Re: Searching a range

    Are you looking for an exact match of the string as the entire cell contents? Or looking for a particular string as any part of cell contents?

    Looking for
    "TEST"

    Is this a match?
    "THIS IS A TEST"

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2407
    Posts
    26,128

    Re: Searching a range

    Here is the concept. This looks in column A for exact matches of the entire cell (above example would not be a match)

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-11-2011
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Searching a range

    OK, thanks for that. It is a partial match with wildcards. I should be able to sort that.If searching many colums is it best to
    include them in the range, or do each one individually?

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2407
    Posts
    26,128

    Re: Searching a range

    Make Range("A:A") whatever your actual range is. OK to make it multiple columns.

    You can use Find for partial matches.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-11-2011
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Searching a range

    Must the range be consecutive? You can't have e.g. Col B and Col F

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2407
    Posts
    26,128

    Re: Searching a range

    The range does not need to be contiguous. You can define any set of cells as a range:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-11-2011
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Searching a range

    Understood.. ideal. Thanks again

+ 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. Find text in a range, select said cell. then continue searching in the range from there
    By sHutchison in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-24-2020, 05:57 PM
  2. Replies: 2
    Last Post: 09-01-2014, 07:59 AM
  3. Replies: 3
    Last Post: 03-04-2011, 02:25 PM
  4. [SOLVED] searching a range for a sum...
    By chickenshed_bob in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-16-2009, 09:09 AM
  5. Searching a range
    By Paul987 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2007, 04:36 PM
  6. searching within a range
    By jcbarnes in forum Excel General
    Replies: 2
    Last Post: 05-30-2007, 10:24 AM
  7. 3d range searching
    By thephoenix12 in forum Excel General
    Replies: 0
    Last Post: 06-15-2005, 01:18 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