+ Reply to Thread
Results 1 to 6 of 6

Run time Error 91 - End Loop not working correctly

  1. #1
    Registered User
    Join Date
    08-04-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    5

    Run time Error 91 - End Loop not working correctly

    I have no knowledge whatever of programming languages so I am hoping that someone can be of help. I need to take a report exported from a Filemaker Pro database as a .pdf document and import the report into Excel 2007. The report can only be exported as a .pdf file. I have saved the .pdf file as a text document and imported the text document into Excel. I have then created a macro by using the record macro function to delete irrelevant data from the column. The difficulty is that when I try to loop the macro to perform the operation through the entire column of data I receive a Error 91 message. I assume that the macro is not ending the loop properly. Below is the code. If anyone can help with how to close the loop properly that would be wonderful.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 08-04-2009 at 04:40 PM. Reason: Added Code Tags

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

    Re: Run time Error 91 - End Loop not working correctly

    Try skipping the loop and using an AUTOFILTER instead. Data > Filter > AutoFilter allows you to selectively filter the data by a value one time, then you can highlight and delete all the visible rows in one go.

    Please Login or Register  to view this content.
    _________________
    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!)

  3. #3
    Registered User
    Join Date
    08-04-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Run time Error 91 - End Loop not working correctly

    Thank you for the suggestion. I will try to implement it.

    The code that I originally posted actually works. But a Run Time Error 91 occurs because the loop is not being closed properly. As a consequence I cannot merge that macro with another similar macro to reduce the number of macros to actually be run.

    rowing190

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Run time Error 91 - End Loop not working correctly

    Hi

    You'll get a runtime error with your original because once all the data has been deleted the Find() method won't return a cell reference and so you can't activate the found cell (thus you get the error). You could control for this like:

    Please Login or Register  to view this content.
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  5. #5
    Registered User
    Join Date
    08-04-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Run time Error 91 - End Loop not working correctly

    Richard:

    Thanks so much for the advice. Your suggestion worked perfectly. I am truly grateful for your helping a complete novice.

    Best,

    rowing190

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

    Re: Run time Error 91 - End Loop not working correctly

    Quote Originally Posted by rowing190 View Post
    Thank you for the suggestion. I will try to implement it.

    The code that I originally posted actually works. But a Run Time Error 91 occurs because the loop is not being closed properly. As a consequence I cannot merge that macro with another similar macro to reduce the number of macros to actually be run.

    rowing190
    The main reason I suggested the alternate approach is that LOOPS have to evaluate each row/cell individually, and you are deleting rows individually. That's a lot of time spent.

    The Auto Filter does the same thing in just a few steps, deleting ALL the matching rows in a single command. It's a faster approach.

    Good call Richard, I missed that completely on the LOOP method.

    =========
    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

+ 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