+ Reply to Thread
Results 1 to 7 of 7

Seaching a Single Column without Selecting

  1. #1
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562

    Seaching a Single Column without Selecting

    How can I take the code listed below and do a search on a single column. In part of the sub I might want to seach Col B and in another part of the sub I might want to search Col J. What do I need to do to this so it will limit the search to a particular column.

    Please Login or Register  to view this content.
    Sincerely,
    Jeff

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525
    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    Thank you! I'll give that a try. There are some days it is easier to ask than search and test for an hour.

    I appreciate the help.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    This example should show you how to build what you want.
    The routine looks through searchColumn looking for the string SearchFor.
    They could be passed to your routine as arguments.

    The address of the first cell is noted, so that the loop can test when .Find loops around to the top of the range again.

    Notice that the Do Loop is inside With EndWith, so that searchColumn applies to .FindNext. Also note that .FindNext needs a starting point (the most recently found cell).

    By avoiding selection, this can be run from when a differnent sheet is active

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    mikerickson,
    Please Login or Register  to view this content.
    Can the "A:A" of .Range("A:A") be set to a variable. I always seem to have trouble with that, but that is actually what I need. If it can be set to a variable, how do I do it.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    searchColumn is a variable.

    Having the Sub take arguments is one way to control it. Four lines would be removed and the declaration would be changed.
    The start of the sub would look like

    Please Login or Register  to view this content.
    And then you could call the routine like

    Please Login or Register  to view this content.
    Note that all occurances of "Dorothy" is being found in both columns D and E. The search can be restricted to any continious range.

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

    Tushar's Findall function at the below link has a little more depth than what you are after but you may still find it useful...

    http://www.tushar-mehta.com/excel/tips/findall.html

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

+ 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