Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Deleting WorkSheets MANY

Application.DisplayAlerts = False
Worksheets("3").Delete
Application.DisplayAlerts = False
Worksheets("4").Delete
Application.DisplayAlerts = False
Worksheets("5").Delete

Is there a way to adapt the above code to simply delete ALL sheets than 2

Tried WorkSheets.Delete"2"
but get an error

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Deleting WorkSheets MANY

On Tue, 4 Jul 2006, Corey wrote:

Application.DisplayAlerts = False
Worksheets("3").Delete
Application.DisplayAlerts = False
Worksheets("4").Delete
Application.DisplayAlerts = False
Worksheets("5").Delete

Is there a way to adapt the above code to simply delete ALL sheets than 2


Change the 20 to the most possible.

Dim i as Integer
Application.DisplayAlerts = False
On Error Resume Next
For i = 2 to 20
Worksheets(i).Delete
Next i
Application.DisplayAlerts = True

Don <www.donwiss.com (e-mail link at home page bottom).
  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Deleting WorkSheets MANY

This seems to work for me. Backup before trying.

Sub DeleteSheets()
Dim i As Long

On Error Resume Next
Application.DisplayAlerts = False

For i = 3 To Worksheets.Count
Worksheets(CStr(i)).Delete
Next i

Application.DisplayAlerts = True
End Sub


"Corey" wrote:

Application.DisplayAlerts = False
Worksheets("3").Delete
Application.DisplayAlerts = False
Worksheets("4").Delete
Application.DisplayAlerts = False
Worksheets("5").Delete

Is there a way to adapt the above code to simply delete ALL sheets than 2

Tried WorkSheets.Delete"2"
but get an error

Corey....



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Deleting WorkSheets MANY

This little macro will do what you want. HTH Otto
Sub Delete3Up()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name 2 Then ws.Delete
Next ws
Application.DisplayAlerts = True
End Sub

"Corey" wrote in message
...
Application.DisplayAlerts = False
Worksheets("3").Delete
Application.DisplayAlerts = False
Worksheets("4").Delete
Application.DisplayAlerts = False
Worksheets("5").Delete

Is there a way to adapt the above code to simply delete ALL sheets than
2

Tried WorkSheets.Delete"2"
but get an error

Corey....



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Deleting WorkSheets MANY


Thanks.

Worked a treat

Cheers

Corey....
"JMB" wrote in message
...
This seems to work for me. Backup before trying.

Sub DeleteSheets()
Dim i As Long

On Error Resume Next
Application.DisplayAlerts = False

For i = 3 To Worksheets.Count
Worksheets(CStr(i)).Delete
Next i

Application.DisplayAlerts = True
End Sub


"Corey" wrote:

Application.DisplayAlerts = False
Worksheets("3").Delete
Application.DisplayAlerts = False
Worksheets("4").Delete
Application.DisplayAlerts = False
Worksheets("5").Delete

Is there a way to adapt the above code to simply delete ALL sheets than
2

Tried WorkSheets.Delete"2"
but get an error

Corey....





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting worksheets David Excel Discussion (Misc queries) 2 January 19th 07 08:19 PM
Deleting Worksheets in VBA Knut Dahl Excel Programming 4 May 23rd 05 07:22 PM
Help deleting worksheets Wilhelmutt Excel Discussion (Misc queries) 2 April 19th 05 03:23 AM
Deleting worksheets Alan L. Wagoner Excel Programming 4 January 24th 05 03:19 PM
Deleting worksheets Oscar Excel Programming 1 July 23rd 04 04:36 AM


All times are GMT +1. The time now is 04:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"