+ Reply to Thread
Results 1 to 13 of 13

Need VB Routine To Search Top to Bottom Without Restarting at Top

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Need VB Routine To Search Top to Bottom Without Restarting at Top

    I have a Find routine as seen below that repeats itself and copies the data to seperate sheet. I need the Find to stop at the last row of data. Can I set this in the SearchOrder:=xlByRows and/or SearchDirection:=xlNext? What should be in the " " on the last line of code?

    Please Login or Register  to view this content.
    Last edited by vlady; 11-15-2012 at 08:10 PM. Reason: code tags

  2. #2
    Forum Contributor
    Join Date
    10-31-2012
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2003/2007
    Posts
    145

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    geshorse,

    in your last row of code
    Please Login or Register  to view this content.
    maybe you could use this instead
    Please Login or Register  to view this content.
    This way if the cell has nothing in it it will just stop?
    I am not sure if it will work with your data but it's worth a shot.


    Simeon

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Maybe you could change your code a little:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    11-05-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Thanks for the reply but this locks up excel where going to task manager and closing excell is required to exit. I have tried variations but with no success.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Try:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-05-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Thanks but this gives me the same results. It copies information to the secondary sheet for each line that is found but then repeats the find over and over again. If there is a command that tells the cell.find to start at top and stop searching when there is no more data witout repeating then that would work. OR If in my "If" statement I could compare the line on the data page that is found to the first line copied to the Lib Search page then Exit Sub could occur when they match.

    Something like:
    If ActiveCell.Value = Sheets("Lib Search").ActiveCell Then Exit Sub Else GoTo SearchLoop

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Can you post the whole routine??

  8. #8
    Registered User
    Join Date
    11-05-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Below is the latest version. The last line I am tring to compare the Active row in the Data Sheet to the First copied row in the Lib Search Sheet. If i can do that and they match then I could Exit Sub. Thanks.

    Please Login or Register  to view this content.

    Moderator's Note: You have to put code tags around your codes. Slect the code then hit the "#" sign.
    Last edited by vlady; 11-16-2012 at 09:15 PM. Reason: code tags

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Hi geshorse,

    I've been playing with your code - see if this even comes close:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-05-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Sorry for the late reply. Away for the holidays then catching up.

    I tried your routine but it did not find the data. I changed it around a bit but still no luck but... If my following question can be done then I believe it will work.

    If a cell has been set to active ie. "Set cCell = ActiveCell"... Let's say it is cell E3 but could be many others... how do you make active the first cell of that Row? In this example E1.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-05-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    Awesome!!! This calls for a celebration. My search and copy routine works! Thanks for all the help everyone! I will post in case anyone can use or make better and use.

    Please Login or Register  to view this content.
    Last edited by geshorse; 11-29-2012 at 10:03 PM. Reason: Place code tags

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need VB Routine To Search Top to Bottom Without Restarting at Top

    You're welcome!

+ 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