Reputation: 1
I am working on an excel dashboard and need to display 2 specific worksheets in the workbook and switch between tabs with an interval of 30 seconds per tab and then return to the first tab and repeat.
I found a macro that is similar to what I need, Excel - Automated Worksheet Switching Loop, however I am trying to only show 2 specific worksheets and not all worksheets in the workbook.
Here is the code that I am using:
Sub StartSlideShow()
Application.OnTime Now + TimeValue("00:00:30"), "ShowNextSheet"
End Sub
Sub ShowNextSheet()
Dim lastIndex As Integer, nextShtIndex As Integer
lastShtIndex = Worksheets.Count
nextShtIndex = ActiveSheet.Index + 1
If nextShtIndex <= lastShtIndex Then
Worksheets(nextShtIndex).Select
StartSlideShow
Else
Worksheets(1).Select
StartSlideShow
End If
End Sub
Upvotes: 0
Views: 167
Reputation: 27259
Something like this:
Sub SlideToOne()
Application.OnTime Now + TimeValue("00:00:30"), "ShowFirstSheet"
End Sub
Sub SlideToTwo()
Application.OnTime Now + TimeValue("00:00:30"), "ShowSecondSheet"
End Sub
Sub ShowFirstSheet()
Worksheets(1).Select
SlideToTwo
End Sub
Sub ShowSecondSheet()
Worksheets(2).Select
SlideToOne
End Sub
Upvotes: 2