Will this code work: Private Sub Worksheet_Deactivate() If…
- User
Will this code work: Private Sub Worksheet_Deactivate() If Worksheets("Notes").Range("B3:B12")<>"" Then Dim answer As VbMsgBoxComplete answer = MsgBox("Do you want to clear Completed Tasks?", vbQuestion + vbYesNo, "Confirmation") If answer = vbYes Then ThisWorkbook.Sheets("Notes").Range("B3:B12").ClearContents Worksheets("Schedule").Range("P1").Calculate Worksheets("Today").Range("I1:J21").Calculate Worksheets("Today").Range("A22").Calculate Worksheets("Today").Range("B1").Calculate Worksheets("Today").Range("F22").Calculate End Sub
- Assistant
No, the code provided will not work as it is missing the 'End If' statement to close the If statement. Here is the corrected code:
Private Sub Worksheet_Deactivate() If Worksheets("Notes").Range("B3:B12") <> "" Then Dim answer As VbMsgBoxResult answer = MsgBox("Do you want to clear Completed Tasks?", vbQuestion + vbYesNo, "Confirmation") If answer = vbYes Then ThisWorkbook.Sheets("Notes").Range("B3:B12").ClearContents Worksheets("Schedule").Range("P1").Calculate Worksheets("Today").Range("I1:J21").Calculate Worksheets("Today").Range("A22").Calculate Worksheets("Today").Range("B1").Calculate Worksheets("Today").Range("F22").Calculate End If End If End Sub