Delete Worksheets

S

Sal

I am using the following macro to delete worksheets in my workbook.

Sub Deleteworksheets()
Sheets("Current Asset").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Current Liability").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Long Term Asset").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Long Term Liability").Select
ActiveWindow.SelectedSheets.Delete
End Sub


The obstacle I am having is that before each sheet deletes I am getting a
message box that reads “Data may exist in the sheet(s) selected for deletion.
To permanently delete the data, press Delete.†I would like to adjust the
macro I have so that it will override this message box and delete the sheets
I have indicated that I want to delete without checking if it is okay. Could
you advise me on how I might do this?
 
J

Jim Thomlinson

Sub Deleteworksheets()
application.displayalerts = false
Sheets("Current Asset").Delete
Sheets("Current Liability").Delete
Sheets("Long Term Asset").Delete
Sheets("Long Term Liability").Delete
application.displayalerts = true
End Sub
 
M

meh2030

I am using the following macro to delete worksheets in my workbook.

Sub Deleteworksheets()
    Sheets("Current Asset").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Current Liability").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Long Term Asset").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Long Term Liability").Select
    ActiveWindow.SelectedSheets.Delete
End Sub

The obstacle I am having is that before each sheet deletes I am getting a
message box that reads “Data may exist in the sheet(s) selected for deletion.
 To permanently delete the data, press Delete.”  I would like to adjust the
macro I have so that it will override this message box and delete the sheets
I have indicated that I want to delete without checking if it is okay.  Could
you advise me on how I might do this?

Sal,

You can use Application.DisplayAlerts = True/False. True shows the
message box result you are referring to, False does not show the
message box result you are referring to. Set DisplayAlters to False
prior to deletion and then set DisplayAlerts to True when you finish
your deletion.

Best,

Matthew Herbert
 
S

Sal

Thank you for your help. This works well now.

Sal,

You can use Application.DisplayAlerts = True/False. True shows the
message box result you are referring to, False does not show the
message box result you are referring to. Set DisplayAlters to False
prior to deletion and then set DisplayAlerts to True when you finish
your deletion.

Best,

Matthew Herbert
 
S

Sal

This works very well. Thank you for your help

Jim Thomlinson said:
Sub Deleteworksheets()
application.displayalerts = false
Sheets("Current Asset").Delete
Sheets("Current Liability").Delete
Sheets("Long Term Asset").Delete
Sheets("Long Term Liability").Delete
application.displayalerts = true
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top