Next Worksheet in code

  • Thread starter Thread starter Gary S
  • Start date Start date
Sub ActivateNextSheet()
Dim index As Integer
index = ActiveSheet.index
If index < Sheets.Count Then
Sheets(index + 1).Activate
Else
Sheets(1).Activate
End If
End Sub


HTH
 
Or

ActiveSheet.Next.Select

Be sure that the last sheet is not active when you run the code
 
Your subroutine can be reduced to this one-liner...

Sub ActivateNextSheet()
Sheets(1 + (Sheets.Count + ActiveSheet.Index) Mod 3).Activate
End Sub

Rick


Ardus Petus said:
Sub ActivateNextSheet()
Dim index As Integer
index = ActiveSheet.index
If index < Sheets.Count Then
Sheets(index + 1).Activate
Else
Sheets(1).Activate
End If
End Sub


HTH
 
Or this (active sheet wraps at last sheet back to first sheet)...

Sheets(1 + (Sheets.Count + ActiveSheet.Index) Mod 3).Select

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top