ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop Until Last Worksheet in Workbook (https://www.excelbanter.com/excel-programming/395312-loop-until-last-worksheet-workbook.html)

[email protected]

Loop Until Last Worksheet in Workbook
 
Hi,

As part of a more complex script, I want this loop to do a set of
actions and then move to the next sheet and preform the same set of
actions and then stop on the last sheet.

Here is what I have so far:

Sub Test
ActiveSheet.Next.Select
Do
<my series of code is here
ActiveSheet.Next.Select
Loop
End Sub

It is working so far, but when I get to the end an error pops up. Not
a big deal, just don't want to have it.

Thanks in advance for your help,
Derrick


Tom Ogilvy

Loop Until Last Worksheet in Workbook
 
Sub Test
ActiveSheet.Next.Select
Do
<my series of code is here
if ActiveSheet.Index < Sheets.count then
ActiveSheet.Next.Select
else
exit do
End if
Loop
End Sub


" wrote:

Hi,

As part of a more complex script, I want this loop to do a set of
actions and then move to the next sheet and preform the same set of
actions and then stop on the last sheet.

Here is what I have so far:

Sub Test
ActiveSheet.Next.Select
Do
<my series of code is here
ActiveSheet.Next.Select
Loop
End Sub

It is working so far, but when I get to the end an error pops up. Not
a big deal, just don't want to have it.

Thanks in advance for your help,
Derrick



[email protected]

Loop Until Last Worksheet in Workbook
 
Thanks so much.




All times are GMT +1. The time now is 11:17 AM.

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