PC Review


Reply
Thread Tools Rate Thread

Delete Worksheets

 
 
Sal
Guest
Posts: n/a
 
      5th May 2009
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?

 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      5th May 2009
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

--
HTH...

Jim Thomlinson


"Sal" wrote:

> 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?
>

 
Reply With Quote
 
meh2030@gmail.com
Guest
Posts: n/a
 
      5th May 2009
On May 5, 3:58*pm, Sal <S...@discussions.microsoft.com> wrote:
> 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
 
Reply With Quote
 
Sal
Guest
Posts: n/a
 
      7th May 2009
Thank you for your help. This works well now.

"(E-Mail Removed)" wrote:

> On May 5, 3:58 pm, Sal <S...@discussions.microsoft.com> wrote:
> > 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
>

 
Reply With Quote
 
Sal
Guest
Posts: n/a
 
      7th May 2009
This works very well. Thank you for your help

"Jim Thomlinson" wrote:

> 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
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Sal" wrote:
>
> > 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?
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete row 1 in all worksheets Jodie Microsoft Excel Programming 7 29th Dec 2009 06:13 PM
Delete All Worksheets Apart From Some With Particular Name =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Misc 1 31st Oct 2007 01:30 AM
Delete All Worksheets, Except for Three =?Utf-8?B?cnlndXk3Mjcy?= Microsoft Excel Programming 1 16th Mar 2007 04:19 PM
I can't delete my worksheets =?Utf-8?B?Y2h1Y2ttY2M=?= Microsoft Excel Programming 7 17th Mar 2006 10:11 PM
Delete worksheets andym Microsoft Excel Programming 6 24th Nov 2003 04:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:15 PM.