Share via

Clear Cells with Warning Message

Anonymous
2012-11-26T06:01:45+00:00

I am using a clear code from

http://answers.microsoft.com/en-us/office/forum/officeversion_other-excel/how-do-i-create-a-button-that-clears-designated/8d5231d2-c286-428b-9092-0f4fa16ad258

Sub ClearCellsMon()

   Application.ScreenUpdating = False ' makes things much faster, no flickering

   With ThisWorkbook.Worksheets("Creator")

         .Range("L10:L29").ClearContents

         .Range("O10:O29").ClearContents

         .Range("P10:P29").ClearContents

         .Range("L32:L36").ClearContents

         .Range("O32:O36").ClearContents

         .Range("P32:P36").ClearContents

         .Range("Z10:Z29").ClearContents

         .Range("AC10:AC29").ClearContents

         .Range("AD10:AD29").ClearContents

    End With

 End Sub

I was wondering if it were possible to show a Warning Message prior clearing the cells after clicking the Macros button?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2012-11-26T07:20:53+00:00

If you merely want to display a message:

Sub ClearCellsMon()

    MsgBox "Click OK to clear a bunch of cells in the Creator sheet.", vbInformation

    Application.ScreenUpdating = False ' makes things much faster, no flickering

    With ThisWorkbook.Worksheets("Creator")

        ...

If you want to give the user a chance to cancel:

Sub ClearCellsMon()

    If MsgBox("Click OK to clear a bunch of cells in the Creator sheet", _

        vbOKCancel + vbQuestion) = vbCancel Then Exit Sub

    Application.ScreenUpdating = False ' makes things much faster, no flickering

    With ThisWorkbook.Worksheets("Creator")

        ...

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-11-26T07:34:30+00:00

    Thanks. That worked like I needed.

    Was this answer helpful?

    0 comments No comments