+ Reply to Thread
Results 1 to 11 of 11

Stop search after going through file once

  1. #1
    Registered User
    Join Date
    08-22-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Stop search after going through file once

    I'm writing a macro that searches for text in a file and then copies the cell and the cell next to it to another sheet.
    I've gotten to the point where it does exactly what I state above but the problem is the search keeps on looping and adding the same values (I added a max of 25 times to the loop for test.
    How do I stop the script when it's found all matches?

    Please Login or Register  to view this content.
    If anyone knows how to do this I would be very happy if they could help me out

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Stop search after going through file once

    Not sure I understand what you're trying to accomplish, so maybe try this on a copy first.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-22-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Stop search after going through file once

    I'm getting a compilation error: Loop without Do.. which is strange since Do is 6 lines about Loop

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Stop search after going through file once

    Can you attach a workbook with some sample data. To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  5. #5
    Registered User
    Join Date
    08-22-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Stop search after going through file once

    Sorry it took some time but I had to change and delete some data since it's a work file.
    I added some text inside the document which should help you understand what is happening and what I want happening.
    Thanks for the help so far
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Stop search after going through file once

    Maybe:

    Please Login or Register  to view this content.
    Sorry I missed an End If in the first code provided.
    Last edited by JOHN H. DAVIS; 08-22-2013 at 01:52 PM.

  7. #7
    Registered User
    Join Date
    08-22-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Stop search after going through file once

    It works now! Thanks a lot!!!
    Just one more question: You have shortened all code's and actions which makes it hard for me to read and alter (since I need it to do some extra stuff every time a match is found).
    Are you willing to (shortly) explain what your code does or split it into some more steps so its easier for me to understand and tinker with?
    Thanks!

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Stop search after going through file once

    You're welcome. Glad to help out.

    This line defines the last row with data in Sheet KKS

    Please Login or Register  to view this content.
    Therefore the loop will start the count with the number of rows with data and end when it reaches 1.

    This line uses the Like operator instead of cells.find

    Please Login or Register  to view this content.
    It basically does the same thing. Just a matter of habit.

    This line copies the activecell range to Sheets("Input") to one row below the last used cell in Column A.
    Please Login or Register  to view this content.
    If you need further explanation, let me know. BTW thanks for the feedback.

  9. #9
    Registered User
    Join Date
    08-22-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Solved: Stop search after going through file once

    Thanks again. I think I get it now. I think I can get on with it now but if I need help or further explanation I'll be back!

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Solved: Stop search after going through file once

    Again welcome. Please comply with Forum Rule No. 9 for this thread. If you need further help from me you can PM.

    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

  11. #11
    Registered User
    Join Date
    08-22-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Stop search after going through file once

    Hehe,
    I didnt know how to mark it as solved so I renamed my reaction to solved.. should me marked solved now though!

+ 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] Creating a VBA loop to search for values, stop when a cell value is 0
    By jfgay in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2013, 10:30 AM
  2. Search and stop
    By djmal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2010, 09:00 PM
  3. Replies: 1
    Last Post: 10-02-2007, 04:10 AM
  4. [SOLVED] Excel '00, 1st file has macros, how to stop macro in 2nd file?
    By kaptandrews in forum Excel General
    Replies: 0
    Last Post: 05-24-2006, 10:15 AM
  5. Replies: 0
    Last Post: 03-29-2005, 11:06 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