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.
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
Note: this goes into the ThisWorkbook code section and not a module. Look to the next section for instructions.
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.
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.