Delete Tabs

J

JohnUK

Hi, I am after a piece of code that will delete all tabs regardless of names
and amounts after a certain tab. In this case the Tab is called “Lastâ€
Any ideas?
Many thanks
 
R

Ryan H

This code will find the index number of the Sheet named "Last". Then it will
delete all the sheets after that sheet without giving you the message box
alert. Hope this helps! If so, let me know, click "YES" below.

Option Explicit

Sub DeleteSheets()

Dim LastSheet As Long
Dim i As Long

Application.DisplayAlerts = False

LastSheet = Sheets("Last").Index + 1

For i = Sheets.Count To LastSheet Step -1
Sheets(i).Delete
Next i

Application.DisplayAlerts = True

End Sub
 
J

JohnUK

Fantastic!!
Many thanks Ryan

Ryan H said:
This code will find the index number of the Sheet named "Last". Then it will
delete all the sheets after that sheet without giving you the message box
alert. Hope this helps! If so, let me know, click "YES" below.

Option Explicit

Sub DeleteSheets()

Dim LastSheet As Long
Dim i As Long

Application.DisplayAlerts = False

LastSheet = Sheets("Last").Index + 1

For i = Sheets.Count To LastSheet Step -1
Sheets(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