Selectnextsheet 2. Selectprevioussheet 3. Go To Selected Sheet

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Contents

1. SelectNextSheet..............................................................................................................................2
2. SelectPreviousSheet........................................................................................................................2
3. Go to Selected Sheet.......................................................................................................................3
1. SelectNextSheet

Sub SelectNextSheet()

'PURPOSE: Select the next visible sheet in the spreadsheet

Dim sht As Worksheet

'Store currently selected sheet

Set sht = ActiveSheet

'Loop to next sheet until visible one is found

On Error Resume Next

Do While sht.Next.Visible <> xlSheetVisible

If Err <> 0 Then Exit Do

Set sht = sht.Next

Loop

'Activate/Select next sheet

sht.Next.Activate

On Error GoTo 0

End Sub

==================================================================================

2. SelectPreviousSheet

Sub SelectPreviousSheet()

'PURPOSE: Select the previous visible sheet in the spreadsheet

Dim sht As Worksheet

'Store currently selected sheet

Set sht = ActiveSheet


'Loop to next sheet until visible one is found

On Error Resume Next

Do While sht.Previous.Visible <> xlSheetVisible

If Err <> 0 Then Exit Do

Set sht = sht.Previous

Loop

'Activate/Select next sheet

sht.Previous.Activate

On Error GoTo 0

End Sub

==================================================================================

3. Go to Selected Sheet

Sub Sheet()

'

' Sheet Macro

Sheets("Sheet2").Select

End Sub

You might also like