Excel Prank - Sheet Jumping

Add to Favorites
Author: | Edits: don

Excel prank that selects the next worksheet in the workbook when the user navigates to another worksheet.

If the user clicks the tab for Sheet1, they will be sent to Sheet 2; this happens for each sheet in the workbook until the user clicks the last worksheet, which sends them back to the first worksheet in the workbook.

Sections:

The Code

Where to Install

Notes

The Code

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'TeachExcel.com

Application.EnableEvents = False

'Number of sheets
SheetCount = Sheets.Count

'Make sure there is more than 1 sheet.
If Not SheetCount > 1 Then Exit Sub

'Check if the sheet selected is the last sheet.
If Sh.Index = SheetCount Then
    SheetToShow = 1
Else
    SheetToShow = Sh.Index + 1
End If

'Navigate to the next sheet.
Sheets(SheetToShow).Activate

Application.EnableEvents = True
End Sub

2b9a4cd3cad277f7fa97739b38244b88.png

Note: this goes into the ThisWorkbook code section and not a module. Look to the next section for instructions.

Where to Install

ThisWorkbook

Alt + F11 (VBA window) > look to the Project window on the left side of the window (Ctrl + R if you don't already see it) > double-click ThisWorkbook > put the code into the window that opens.

You need to put the code here so that it will run for the entire workbook and not just a specific worksheet.

Notes

The only way to stop this prank is to go to the VBA window and remove the code.

Download the attached file to see this prank in Excel.


Downloadable Files: Excel File

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Tutorial Details
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course