I have found these two codes for moving to the next/previous visible sheets.
Sub NextSheet()![]()
Please Login or Register to view this content.
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
Sub PrevSheet()
Set Sh = ActiveSheet
On Error Resume Next
Do While Sh.Previous.Visible <> xlSheetVisible
If Err <> 0 Then Exit Do
Set Sh = Sh.Previous
Loop
Sh.Previous.Activate
On Error GoTo 0
End Sub
I have a workbook with 50 works sheets (some sheets are hidden). I created two command buttons on each sheet (“<Back” and “Next>”) and connected them with relevant codes. It all works well.![]()
Please Login or Register to view this content.
The only issue I have is that when moving from one sheet (say Sheet2) to the next sheet (say Sheet3) I end up in the last active cell in the destination sheet. For example, if the last active cell in Sheet3 was “A23” I will end up in that cell when pressing “Next>” button in Sheet2 or “<Back” button in Sheet4.
Can anyone assist me to modify these codes so that when moves are made (either to the next or previous unhidden sheet) I always end up in a same destination in each worksheet sheet (say cell “A1”).
Many thanks in advance
Bookmarks