ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Advancing outer Loop Based on criteria of inner loop (https://www.excelbanter.com/excel-programming/337281-advancing-outer-loop-based-criteria-inner-loop.html)

ExcelMonkey

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(Worksheet s(AuditShtName).Range("B2:B65536"))
NExt
Next
Next

Thanks

Tom Ogilvy

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" wrote in message
...
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(Worksheet s(AuditShtName).Range("B2:
B65536"))
NExt
Next
Next

Thanks





All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com