DeepUnderground
07-20-2010, 04:33 PM
HI I have the following:
For Each mysheet In Worksheets
mysheet.select
Next
In the workbook say there are 30 worksheets, but I only want to go through the first 5 sheets with the for loop. Is there another way to exit the for loop without adding an counter on the inside of the loop. For example:
i = 0
For Each mysheet In Worksheets
i = i+1
if i > 5 then
exit for
end if
mysheet.select
Next
For Each mysheet In Worksheets
mysheet.select
Next
In the workbook say there are 30 worksheets, but I only want to go through the first 5 sheets with the for loop. Is there another way to exit the for loop without adding an counter on the inside of the loop. For example:
i = 0
For Each mysheet In Worksheets
i = i+1
if i > 5 then
exit for
end if
mysheet.select
Next