Button to open next worksheet doesn't work.

Ronanm

Board Regular
Joined
Nov 13, 2010
Messages
107
I had the code below on a button, but when I press the button nothing happens, I am on sheet 1 of 31 when I press the buton.

Any ideas from anyone?

Code:
Sub NextSheet()
    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
    sh.Visible = False
End Sub

Thanks

Ronan
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This worked for me, you may need to tweak it for your purposes:
Code:
Sub test()
Dim i As Integer
i = ActiveSheet.Index
On Error Resume Next
i = i + 1
Do While Sheets(i).Visible = False
    i = i + 1
Loop
Sheets(i).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,848
Messages
6,138,977
Members
450,170
Latest member
auxplaines

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top