ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Next Worksheet in code (https://www.excelbanter.com/excel-programming/404855-next-worksheet-code.html)

Gary S[_2_]

Next Worksheet in code
 
Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S

Smallweed

Next Worksheet in code
 
Worksheets(ActiveSheet.Index+1).Activate

"Gary S" wrote:

Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S


Ardus Petus

Next Worksheet in code
 
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
--
AP

"Gary S" a écrit dans le message de news:
...
Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S




Ron de Bruin

Next Worksheet in code
 
Or

ActiveSheet.Next.Select

Be sure that the last sheet is not active when you run the code


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Smallweed" wrote in message ...
Worksheets(ActiveSheet.Index+1).Activate

"Gary S" wrote:

Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S


Rick Rothstein \(MVP - VB\)

Next Worksheet in 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" wrote in message
...
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
--
AP

"Gary S" a écrit dans le message de
news: ...
Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S





Rick Rothstein \(MVP - VB\)

Next Worksheet in code
 
Or this (active sheet wraps at last sheet back to first sheet)...

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

Rick


"Ron de Bruin" wrote in message
...
Or

ActiveSheet.Next.Select

Be sure that the last sheet is not active when you run the code


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Smallweed" wrote in message
...
Worksheets(ActiveSheet.Index+1).Activate

"Gary S" wrote:

Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S




All times are GMT +1. The time now is 03:36 PM.

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