+ Reply to Thread
Results 1 to 4 of 4

Stop searching for file once a match is found.

  1. #1
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Question Stop searching for file once a match is found.

    I am currently running a macro that searches for a file with a rotating filename.

    The current code I am using works fine. However it returns and opens multiple files. I am using numerous search criteria as the file changes daily based on the time it was saved. I am trying to figure a way to stop the search once it finds a match and continue on with the rest of the macro.

    Please Login or Register  to view this content.
    Last edited by CJPHX; 05-21-2010 at 12:40 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Stop searching for file once a match is found.

    You could add a line saying if the workbook is added, skip the rest:

    Please Login or Register  to view this content.
    The above code replaces all the code you posted.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Stop searching for file once a match is found.

    Like this perhaps:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-21-2010 at 12:27 PM. Reason: Added check in case none are foudn in all the locations, aborts macro.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: Stop searching for file once a match is found.

    Thank you. JBeaucaire, that worked for me.

+ 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