Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ActiveSheet.Next with hidden sheets

Hello,

I currently have a spreadsheet that has a 'veryhidden' sheet.

I have written a macro to navigate foward and backwards throughout the
spreadsheet, however, when it gets to the hidden sheets location, the macro
will not skip over it.

Macro:
ActiveSheet.Next.Select
Even when I use the macro recorder, the code is as per above?!?!

I have found that the error is:
1004, 'Select method of worksheet class failed'.

I have managed to use the errorhandler to move past this by calling the next
sheet by name, but fear this sheetname may get changed in the future.... is
there anyway of retrieving the sheet index number?

Thanks,
KK

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default ActiveSheet.Next with hidden sheets

Try this

On Error Resume Next
ActiveSheet.Next.Select
Do While Err.Number < 0
Err.Clear
Worksheets(ActiveSheet.Index + 2).Select
Loop
On Error Goto 0

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"KurviousKoala" wrote in message
...
Hello,

I currently have a spreadsheet that has a 'veryhidden' sheet.

I have written a macro to navigate foward and backwards throughout the
spreadsheet, however, when it gets to the hidden sheets location, the
macro
will not skip over it.

Macro:
ActiveSheet.Next.Select
Even when I use the macro recorder, the code is as per above?!?!

I have found that the error is:
1004, 'Select method of worksheet class failed'.

I have managed to use the errorhandler to move past this by calling the
next
sheet by name, but fear this sheetname may get changed in the future....
is
there anyway of retrieving the sheet index number?

Thanks,
KK



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default ActiveSheet.Next with hidden sheets

Actually, there is a problem if there is more than one very hidden sheets
next to each other.

This overcomes that

Dim nSkip As Long
On Error Resume Next
Do
Err.Clear
nSkip = nSkip + 1
Worksheets(ActiveSheet.Index + nSkip).Select
Loop Until Err.Number = 0


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"KurviousKoala" wrote in message
...
Fab!!! thanks a million :-)

"Bob Phillips" wrote:

Try this

On Error Resume Next
ActiveSheet.Next.Select
Do While Err.Number < 0
Err.Clear
Worksheets(ActiveSheet.Index + 2).Select
Loop
On Error Goto 0

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"KurviousKoala" wrote in
message
...
Hello,

I currently have a spreadsheet that has a 'veryhidden' sheet.

I have written a macro to navigate foward and backwards throughout the
spreadsheet, however, when it gets to the hidden sheets location, the
macro
will not skip over it.

Macro:
ActiveSheet.Next.Select
Even when I use the macro recorder, the code is as per above?!?!

I have found that the error is:
1004, 'Select method of worksheet class failed'.

I have managed to use the errorhandler to move past this by calling the
next
sheet by name, but fear this sheetname may get changed in the
future....
is
there anyway of retrieving the sheet index number?

Thanks,
KK






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ActiveSheet.Next with hidden sheets

Interesting problem:

Sub Nextsheet()
Dim sh As Object
If ActiveSheet.Index = Sheets.Count Then
MsgBox "At the last sheet"
Exit Sub
End If
Set sh = ActiveSheet.Next
Do While sh.Visible < xlSheetVisible
If sh.Index < Sheets.Count Then
Set sh = sh.Next
Else
MsgBox "Last visible sheet is selected"
Exit Sub
End If
Loop
sh.Select
End Sub


is a slightly different approach.

--
Regards,
Tom Ogilvy

"KurviousKoala" wrote in message
...
Fab!!! thanks a million :-)

"Bob Phillips" wrote:

Try this

On Error Resume Next
ActiveSheet.Next.Select
Do While Err.Number < 0
Err.Clear
Worksheets(ActiveSheet.Index + 2).Select
Loop
On Error Goto 0

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"KurviousKoala" wrote in
message
...
Hello,

I currently have a spreadsheet that has a 'veryhidden' sheet.

I have written a macro to navigate foward and backwards throughout the
spreadsheet, however, when it gets to the hidden sheets location, the
macro
will not skip over it.

Macro:
ActiveSheet.Next.Select
Even when I use the macro recorder, the code is as per above?!?!

I have found that the error is:
1004, 'Select method of worksheet class failed'.

I have managed to use the errorhandler to move past this by calling the
next
sheet by name, but fear this sheetname may get changed in the
future....
is
there anyway of retrieving the sheet index number?

Thanks,
KK






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
hidden sheets Soccerboy83 Excel Discussion (Misc queries) 5 November 25th 09 06:17 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM
"With Sheets" Issue - macro on one sheet to affect hidden rows on other sheets Punsterr Excel Programming 3 February 21st 06 04:01 AM
Hidden sheets TAM Excel Programming 1 February 4th 06 10:03 AM
ActiveSheet.ShowAllData shows everything - way to have hidden _not_ show up? StargateFanFromWork Excel Programming 1 July 8th 04 04:33 AM


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

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"