Yes / No is understood. But what will the cancelled option do?
Anyway, a very simple way to do this is
Code:Private Sub CommandButton1_Click() If vbYes = MsgBox("Are you sure you want to delete", vbYesNo + vbQuestion, "Clear Cell Contents") Then Range("F7:L13,F18:L24,F29:L35").ClearContents End If End Sub
But a more elaborate one which can be used to different actions based on response
Code:Private Sub CommandButton1_Click() Dim vblResponse As VbMsgBoxResult vblResponse = MsgBox("Are you sure you want to delete", vbYesNoCancel + vbQuestion, "Clear Cell Contents") If vblResponse = vbYes Then Range("F7:L13,F18:L24,F29:L35").ClearContents ElseIf vblResponse = vbNo Then 'Code here if user clicked no ElseIf vblResponse = vbCancel Then 'Code here if user clicked cancel End If End Sub




Reply With Quote
Bookmarks