Delete Tabs

  • Thread starter Thread starter JohnUK
  • Start date Start date
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
 
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
 
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
 
Back
Top