+ Reply to Thread
Results 1 to 13 of 13

Loop Through Workbooks - Compile Error

  1. #1
    Registered User
    Join Date
    03-28-2017
    Location
    birmingham
    MS-Off Ver
    2013
    Posts
    5

    Question Loop Through Workbooks - Compile Error

    I am trying to loop through my open workbooks (which are all in the same format) and filter for the values I have selected in the workbook "Amendments Mar17.xlsx" workbook.

    I keep getting the following Error on the Final "End If" of my code. which makes no sense to me as I have an "If"?

    The Error Message is:
    Compile Error:
    End IF without Block If


    My Code is:

    Please Login or Register  to view this content.
    [CODE/]
    Last edited by Tom741; 04-07-2017 at 04:10 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Loop Through Workbooks - Compile Error

    Move "End With" to inside the loop before End If.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Loop Through Workbooks - Compile Error

    Deleted post.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    03-28-2017
    Location
    birmingham
    MS-Off Ver
    2013
    Posts
    5

    Re: Loop Through Workbooks - Compile Error

    Sorry. I have now done this.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Loop Through Workbooks - Compile Error

    Thanks for the code tag.
    Did you
    Quote Originally Posted by jindon View Post
    Move "End With" to inside the loop before End If.
    ?

  6. #6
    Registered User
    Join Date
    03-28-2017
    Location
    birmingham
    MS-Off Ver
    2013
    Posts
    5

    Re: Loop Through Workbooks - Compile Error

    Thanks Jindon

    This has sorted out the compile error - Silly mistake by me.

    however I am not getting an error on the line.

    Please Login or Register  to view this content.
    It says Subscript out of range.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Loop Through Workbooks - Compile Error

    That says ws have no sheet named "Bdx", I suspect.

  8. #8
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Loop Through Workbooks - Compile Error

    The worksheet 'bdx' does not exist in the workbook referred to by wb...

  9. #9
    Registered User
    Join Date
    03-28-2017
    Location
    birmingham
    MS-Off Ver
    2013
    Posts
    5

    Re: Loop Through Workbooks - Compile Error

    Hmmm... Thats what I thought it meant but I have two workbooks open, both containing Worksheets Called "Bdx"

    Could the code not be looking at all open workbooks???

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Loop Through Workbooks - Compile Error

    Try check the wb name, or loop through all the worksheet in wb and find out if the name is correct or not?

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Loop Through Workbooks - Compile Error

    Do you want to try something like this?
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    03-28-2017
    Location
    birmingham
    MS-Off Ver
    2013
    Posts
    5

    Re: Loop Through Workbooks - Compile Error

    I changed the "PERSONAL.xlsb" to "PERSONAL.XLSB" and the code worked. I didn't know that would cause a problem!

    Thanks for the help!

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Loop Through Workbooks - Compile Error

    Yep, that's case sensitive... and thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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] Getting compile error 'loop without do'
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2015, 11:43 AM
  2. compile error: loop without do
    By phoenix073 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2014, 03:44 PM
  3. [SOLVED] Compile error do without loop
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-29-2013, 08:34 PM
  4. Loop without Do compile error
    By Dulanic in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2010, 12:12 PM
  5. Compile Error: Loop without Do
    By iii in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-24-2009, 06:41 PM
  6. Compile Error: Loop without Do
    By cedtech23 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-01-2006, 07:58 PM
  7. [SOLVED] Compile error: Loop WIthout Do
    By darin kelberlau in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2005, 01:55 PM

Tags for this Thread

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