ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting WorkSheets MANY (https://www.excelbanter.com/excel-programming/366142-deleting-worksheets-many.html)

Corey

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



Don Wiss

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).

JMB

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




Otto Moehrbach

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




Corey

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







All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com