Deleting WorkSheets MANY

C

Corey

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

Don Wiss

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

Guest

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
 
O

Otto Moehrbach

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
 
C

Corey

Thanks.

Worked a treat

Cheers

Corey....
JMB said:
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
 

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