-1

I have created a VBA and have tried to add a MsgBox to confirm I do want to continue. The MsgBox appears but does not respond if I click OK or X.I was hoping to be given a Yes/No choice.

Sub Clear_sheet()

ActiveSheet.Unprotect
 Dim AnswerYes As String
 Dim AnswerNo As String
 AnswerYes = MsgBox("Are you sure?", vbQuestion + YesNo, "User Response")
If AnswerYes = vbYes Then
  Range("T32 , AB32").Select
  Selection.ClearContents
  Range("B4:B32").Select
  Selection.ClearContents
  Range("W11").Select
Else
End If
ActiveSheet.Protect

End Sub

My code also has many more ranges to ClearContents. I'm wondering if the VBA will be improved with fewer lines with the ranges separated with a comma?

Many thanks for your time.

Progman
  • 16,827
  • 6
  • 33
  • 48
MrEMann
  • 1
  • 1

1 Answers1

0

I have found the answer I needed on Google

ActiveSheet.Unprotect "Password here" Dim AnswerYes As String Dim AnswerNo As String AnswerYes = MsgBox("Do you wish to continue?", vbQuestion + vbYesNo, "User Repsonse") If AnswerYes = vbYes Then

  Code to action entered here

 Else
End If
ActiveSheet.Protect "Password here"

End Sub

MrEMann
  • 1
  • 1