When the code below runs, the message is shown after I leave the sheet. I want the…
- User
When the code below runs, the message is shown after I leave the sheet. I want the message to show before I leave the sheet. Private Sub Worksheet_Deactivate() Dim response As VbMsgBoxResult ' Display the message box with Yes and No buttons response = MsgBox("Would you like to check All Premises Requests?", vbQuestion + vbYesNo, "Exit Worksheet") ' If the user selects Yes, activate the 'RequestClean' worksheet If response = vbYes Then Worksheets("Request Events").Activate End If End Sub
- Assistant
To show the message before leaving the sheet, you can use the Worksheet_BeforeDoubleClick event instead of the Worksheet_Deactivate event. Here is an example of how you can modify your code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim response As VbMsgBoxResult
code' Display the message box with Yes and No buttons response = MsgBox("Would you like to check All Premises Requests?", vbQuestion + vbYesNo, "Exit Worksheet") ' If the user selects Yes, activate the 'Request Events' worksheet If response = vbYes Then Worksheets("Request Events").Activate End IfEnd Sub
This code will show the message box when the user double-clicks on any cell in the sheet.