ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Tabs (https://www.excelbanter.com/excel-programming/438580-delete-tabs.html)

JohnUK

Delete Tabs
 
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


Ryan H

Delete Tabs
 
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

--
Cheers,
Ryan


"JohnUK" wrote:

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


JohnUK

Delete Tabs
 
Fantastic!!
Many thanks Ryan

"Ryan H" wrote:

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

--
Cheers,
Ryan


"JohnUK" wrote:

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



All times are GMT +1. The time now is 09:44 PM.

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