+ Reply to Thread
Results 1 to 10 of 10

For Next Loop

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    For Next Loop

    Hi,

    For some reason I can't get this loop to work. The Max function finds the largest value in column A and the loop looks through the rows to locate the row and displays it through MsgBox. However I keep getting a "End if without block if" error. Any help would be great.


    Please Login or Register  to view this content.
    amphi

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: For Next Loop


    Hi,

    yes, you must place line End If before line Exit For ! …

  3. #3
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: For Next Loop

    I also tried that but I get the same error.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: For Next Loop

    Also, why you need loop?

    This will do the same:
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: For Next Loop

    Remove underscore from end of this line:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  6. #6
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: For Next Loop

    Or

    In the If block you could say 'goto EXIT10' instead of 'Exit for'
    and set a label just above end sub.
    Label to start at the start of the line, not indented and to read "Exit:"
    Click * below if this answer helped

  7. #7
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: For Next Loop

    You should not have the line break character (space and underscore) after the THEN statement
    The THEN statement is a natural break to the next line.

    Please Login or Register  to view this content.
    Good catch zbor... The function evaluates the entire range anyways
    Last edited by RudiS; 03-31-2014 at 05:33 AM.
    Regards,
    Rudi

  8. #8
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: For Next Loop

    Thanks guys appreciate it. The Match function worked perfectly. Izandol I removed the underscore but I still get the same error...

  9. #9
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: For Next Loop

    Got it thanks RudiS.

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: For Next Loop

    Quote Originally Posted by amphinomos View Post
    Izandol I removed the underscore but I still get the same error...
    I do not think this is possible (it would be same code Rudi posted).

+ 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] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  2. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  3. Macro Loop Broken. Detects Max but doesn't continue loop
    By herchenbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2011, 12:17 PM
  4. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  5. Loop a column on Sheet1 and loop a row on Sheet2 to find a match
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2009, 02:09 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