+ Reply to Thread
Results 1 to 2 of 2

Advancing outer Loop Based on criteria of inner loop

  1. #1
    ExcelMonkey
    Guest

    Advancing outer Loop Based on criteria of inner loop

    I have a bunch of nested For Loops. They loop through sheets then loop
    through certain search routines, and then loop through cells. Within the
    third For Loop I have a counter called SummarySheetRowCounter. When this
    reaches 65536, I want to be able to stop what is happening in the third loop,
    and then advance the Second Loop (SearchType). How do I exit the third loop
    without ending the entire sub routine? Note that I could have preceeded the
    third loop with an IF statement saying if SummarySheetRowCounter <> 65536
    Then do what you do in third loop. But this will not work as the counter
    needs to increment within this third loop. An If statement outside of this
    third loop will not have visiblity to the counter value to make the If work.
    What can I do to do this properly?

    For Each Sheet in Worksheets
    For SearchType = 1 to 10
    For Each cell in Cells
    'Code that prints results in rows of sheet
    SummarySheetRowCounter =
    Application.WorksheetFunction.CountBlank(Worksheets(AuditShtName).Range("B2:B65536"))
    NExt
    Next
    Next

    Thanks

  2. #2
    Tom Ogilvy
    Guest

    Re: Advancing outer Loop Based on criteria of inner loop

    For Each Sheet in Worksheets
    For SearchType = 1 to 10
    For Each cell in Cells
    'Code that prints results in rows of sheet
    SummarySheetRowCounter = _
    Application.WorksheetFunction.CountBlank( _
    Worksheets(AuditShtName).Range("B2:B65536"))
    if summarysheetrowcount >= 65535 then exit for
    NExt
    Next
    Next

    You will never get a summarysheetrowcount equal to 65536 since you are only
    counting 65535 cells.

    --
    Regards,
    Tom Ogilvy


    "ExcelMonkey" <[email protected]> wrote in message
    news:[email protected]...
    > I have a bunch of nested For Loops. They loop through sheets then loop
    > through certain search routines, and then loop through cells. Within the
    > third For Loop I have a counter called SummarySheetRowCounter. When this
    > reaches 65536, I want to be able to stop what is happening in the third

    loop,
    > and then advance the Second Loop (SearchType). How do I exit the third

    loop
    > without ending the entire sub routine? Note that I could have preceeded

    the
    > third loop with an IF statement saying if SummarySheetRowCounter <> 65536
    > Then do what you do in third loop. But this will not work as the counter
    > needs to increment within this third loop. An If statement outside of

    this
    > third loop will not have visiblity to the counter value to make the If

    work.
    > What can I do to do this properly?
    >
    > For Each Sheet in Worksheets
    > For SearchType = 1 to 10
    > For Each cell in Cells
    > 'Code that prints results in rows of sheet
    > SummarySheetRowCounter =
    >

    Application.WorksheetFunction.CountBlank(Worksheets(AuditShtName).Range("B2:
    B65536"))
    > NExt
    > Next
    > Next
    >
    > Thanks




+ 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