Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Adding criteria to loop | Excel Worksheet Functions | |||
Problem adding charts using Do-Loop Until loop | Excel Programming | |||
Advancing to the next iteration of a loop? | Excel Programming | |||
3 range criteria for Loop | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming |