Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default moving to next worksheet

I have a workbook with several worksheets. I hide some worksheets for
various reasons. I have navigation buttons on each worksheet that are
support to go to the previous or the next worksheet. The macro code I'm
using is:

Prev: ActiveSheet.Previous.Next

Next: ActiveSheet.Next.Select

If the next sheet has been hidden, I get a run-time error '1004'. How
can I move to the next visible worksheet ?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default moving to next worksheet

Sub AA()

Set sh = ActiveSheet
On Error Resume Next
Do While sh.Next.Visible < xlSheetVisible
If Err < 0 Then Exit Do
Set sh = sh.Next
Loop
sh.Next.Activate
On Error GoTo 0

End Sub



--
Regards,
Tom Ogilvy

"Kent McPherson" wrote in message
...
I have a workbook with several worksheets. I hide some worksheets for
various reasons. I have navigation buttons on each worksheet that are
support to go to the previous or the next worksheet. The macro code I'm
using is:

Prev: ActiveSheet.Previous.Next

Next: ActiveSheet.Next.Select

If the next sheet has been hidden, I get a run-time error '1004'. How
can I move to the next visible worksheet ?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default moving to next worksheet

Tom Ogilvy wrote:
Sub AA()

Set sh = ActiveSheet
On Error Resume Next
Do While sh.Next.Visible < xlSheetVisible
If Err < 0 Then Exit Do
Set sh = sh.Next
Loop
sh.Next.Activate
On Error GoTo 0

End Sub




Thanks! Works perfectly.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default moving to next worksheet


Hi, this is the way I always did int Excel 2000. I know its not a goo
code at all. I'm a beginner myself. I appreciate any kind of comments.

Sub GoToPrevioustSheet()

Dim idx As Integer

idx = ActiveSheet.Index
If idx = 1 Then
MsgBox "This is the first sheet"
Exit Sub
ElseIf Sheets(idx - 1).Visible = False Then
Do Until Sheets(idx - 1).Visible = True
idx = idx - 1
Loop
Sheets(idx - 1).Select
Else
Sheets(idx - 1).Select
End If

End Sub

Sub GoToNextSheet()

Dim idx As Integer

idx = ActiveSheet.Index
If idx = Sheets.Count Then
MsgBox "This is the last sheet"
Exit Sub
ElseIf Sheets(idx + 1).Visible = False Then
Do Until Sheets(idx + 1).Visible = True
idx = idx + 1
Loop
Sheets(idx + 1).Select
Else
Sheets(idx + 1).Select
End If

End Su

--
hidek
-----------------------------------------------------------------------
hideki's Profile: http://www.excelforum.com/member.php...fo&userid=1890
View this thread: http://www.excelforum.com/showthread.php?threadid=39335

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
Moving within the worksheet ordnance1 Excel Worksheet Functions 3 March 28th 08 03:45 AM
Moving a Worksheet jpiseler Excel Discussion (Misc queries) 6 September 6th 07 01:10 AM
moving a worksheet..? Roy Excel Discussion (Misc queries) 2 September 29th 06 02:56 AM
Moving between the tabs on a worksheet Sarah B Excel Discussion (Misc queries) 3 April 11th 06 12:16 PM
Need help i moving one worksheet to another psk[_7_] Excel Programming 1 November 12th 04 04:00 PM


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

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

About Us

"It's about Microsoft Excel"