Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding criteria to loop Andyjim Excel Worksheet Functions 0 January 13th 08 08:54 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Advancing to the next iteration of a loop? Maury Markowitz Excel Programming 4 April 2nd 05 05:39 PM
3 range criteria for Loop hotherps[_47_] Excel Programming 0 April 14th 04 06:02 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 04:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"