Excelシート移動 †Ctrl+PgUp?、Ctrl+PgDn?で移動するのは面倒で遅いため、マクロ化を考えました。 2019/10/15 改良版 †Sub prevSheet()
Set SH = ActiveWorkbook.ActiveSheet
Set STS = ActiveWorkbook.Sheets
On Error Resume Next
''左のシートへ。最初なら末尾に
If SH.Name = STS(1).Name Then
STS(STS.Count).Activate
Else
''非表示のシートは飛ばす
Do While SH.Previous.Visible <> xlSheetVisible
If Err <> 0 Then Exit Do
Set SH = SH.Previous
Loop
If SH.Previous.Visible <> xlSheetVisible And SH.Previous.Name = STS(1).Name Then
STS(STS.Count).Activate
Else
SH.Previous.Activate
End If
On Error GoTo 0
End If
End Sub
Sub nextSheet()
Set SH = ActiveWorkbook.ActiveSheet
Set STS = ActiveWorkbook.Sheets
On Error Resume Next
''右のシートへ。末尾なら最初に
If SH.Name = STS(STS.Count).Name Then
STS(1).Activate
Else
''非表示のシートは飛ばす
Do While SH.Next.Visible <> xlSheetVisible
If Err <> 0 Then Exit Do
Set SH = SH.Next
Loop
If SH.Next.Visible <> xlSheetVisible And SH.Next.Name = STS(STS.Count).Name Then
STS(1).Activate
Else
SH.Next.Activate
End If
On Error GoTo 0
End If
End Sub
シンプル初期版 †Sub prevSheet()
If 1 < ActiveSheet.Index Then ' 最初のシートでないなら '
ActiveSheet.Previous.Select ' 前のシートに移動する '
End If
End Sub
Sub nextSheet()
If Worksheets.Count > ActiveSheet.Index Then ' 最後のシートでないなら '
ActiveSheet.Next.Select ' 次のシートに移動する '
End If
End Sub
参考ページ † |