gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
I would like to have a Yes No message when I leave a worksheet that says; "Would you…
- User
I would like to have a Yes No message when I leave a worksheet that says; "Would you like to check All Cleaning Requests?" If I answer yes, then the worksheet 'RequestClean' is Activated
- Assistant
To achieve this functionality, you can use the Worksheet_Deactivate event in VBA. Here's an example code that you can place in the worksheet module where you want the message to appear:
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 Cleaning Requests?", vbQuestion + vbYesNo, "Exit Worksheet") ' If the user selects Yes, activate the 'RequestClean' worksheet If response = vbYes Then Worksheets("RequestClean").Activate End If End SubHere's how to add the code to your workbook:
- Press Alt+F11 to open the VBA Editor.
- In the Project Explorer window, locate and double-click on the worksheet module where you want the message to appear (e.g., Sheet1).
- Paste the above code into the code window.
- Close the VBA Editor.
Now, whenever you leave the worksheet, the message box will appear, and if you click Yes, it will activate the 'RequestClean' worksheet.