I am trying to write some Visual Basic code so that someone does not accidentally rewrite cells on multiple sheets when selecting multiple sheets.
However, I need the option to overwrite cells on multiple sheets, if necessary at any stage.
So, when I have selected several sheets, I would like to pop up with two options: "Are you sure you want to rewrite the cells on the sheets that you selected?" Ok Cancel
I think I'm almost there with the code below, but if I have 3 sheets, a popup will appear 3 times (once for each page). Naturally, I want the popup to be displayed once no matter how many sheets I have selected.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) If ActiveWindow.SelectedSheets.Count > 1 Then If MsgBox("Are you sure you want to overwrite the cells across the sheets you have selected?", vbOKCancel) = vbCancel Then Exit Sub Application.EnableEvents = False Application.Undo End If Application.EnableEvents = True End Sub
Or even the best solution actually:
"Do you really want to rewrite the cells to the sheets you selected?"
Yes (to continue all selected pages),
No (to select the current page and continue),
Cancel (to cancel the operation and save the current selection).
source share