+ Reply to Thread
Results 1 to 4 of 4

Next Without For Compile Error

  1. #1
    Registered User
    Join Date
    01-08-2016
    Location
    Chicago
    MS-Off Ver
    MS Excel 2010
    Posts
    2

    Next Without For Compile Error

    Hello everyone,

    I'm new to this excel forum site but have done a little bit of vba coding. My code below keeps getting a next without for compile error but I cannot figure out what is wrong. Both if statements have end ifs which is usually the reason for such an error. Any ideas on what the issue is?

    Please Login or Register  to view this content.
    Last edited by jmbosma; 01-08-2016 at 02:58 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,630

    Re: Next Without For Compile Error

    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.

    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


    You don't need the End If when the instruction is on the same line as the Then


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-08-2016
    Location
    Chicago
    MS-Off Ver
    MS Excel 2010
    Posts
    2

    Re: Next Without For Compile Error

    Thanks for the note TMS. I started out with the code that way but it received the same error. I just removed the End ifs as seen below and am still seeing the same error. Any more ideas?
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,863

    Re: Next Without For Compile Error

    I don't know if it is documented anywhere, but I don't think you can have a "Next" as part of a If then statement.

    When you want to conditionally perform the statements within a For..Next loop, the usual code structure I see is where one usually tests for "If test is not true, then perform steps in loop". Something like:
    Please Login or Register  to view this content.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  2. [SOLVED] Compile Error in Hidden Module and Compile Error: Can't find project or library
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2013, 07:03 PM
  3. [SOLVED] Compile error: Constant expression required error when merging two Codes
    By Kezwick in forum Outlook Programming / VBA / Macros
    Replies: 8
    Last Post: 06-26-2013, 09:32 AM
  4. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM
  5. compile error: compile error expected
    By odeno in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2008, 04:30 PM
  6. Replies: 1
    Last Post: 02-17-2006, 12:10 PM
  7. Replies: 3
    Last Post: 02-13-2006, 11:30 AM
  8. [SOLVED] VBAProject name compile error, not defined at compile time
    By Matthew Dodds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2005, 03:20 PM

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