Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Next Worksheet in code

Basic vba question.

How do I go to the next worksheet using code?
--
Thanks for your help!
Gary S
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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


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
how to prevent code running when in a worksheet code Corey Excel Programming 5 August 13th 06 08:52 AM
Code Conflicts With Worksheet Change Code Paige Excel Programming 3 March 3rd 06 04:25 PM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Excel Programming 4 June 15th 05 04:37 PM
Altering code to reference the worksheet before the active worksheet KimberlyC Excel Programming 8 March 15th 05 10:26 PM
Return to previous worksheet after code pastes in another worksheet? Ron[_28_] Excel Programming 4 September 4th 04 07:52 PM


All times are GMT +1. The time now is 05:04 AM.

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

About Us

"It's about Microsoft Excel"