ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting every sheet in workbook after Worksheets(4) (https://www.excelbanter.com/excel-programming/286681-deleting-every-sheet-workbook-after-worksheets-4-a.html)

Todd Huttenstine[_3_]

Deleting every sheet in workbook after Worksheets(4)
 
Hey guys,

What is the code to delete every sheet in the active workbook from
worksheets(4) onward? I want to keep sheets 1-4 but delete the rest.


Thanx

Todd Huttenstine



David Coleman[_2_]

Deleting every sheet in workbook after Worksheets(4)
 
Hi Todd

Something like

Sub macro1()
Dim totalsheets As Integer

'Application.DisplayAlerts = False 'uncomment this line to delete
without prompting - don't forget to set to true once done!

totalsheets = ActiveWorkbook.Sheets.Count
While (5 <= totalsheets)
ActiveWorkbook.Sheets(5).Delete
totalsheets = totalsheets - 1
Wend
End Sub



should do you (prompting to delete each sheet first) - make a backup of your
file before testing this one!

Regards

David


"Todd Huttenstine" wrote in message
...
Hey guys,

What is the code to delete every sheet in the active workbook from
worksheets(4) onward? I want to keep sheets 1-4 but delete the rest.


Thanx

Todd Huttenstine





Todd Huttenstine[_3_]

Deleting every sheet in workbook after Worksheets(4)
 
Thank you

Todd


"David Coleman" wrote in message
...
Hi Todd

Something like

Sub macro1()
Dim totalsheets As Integer

'Application.DisplayAlerts = False 'uncomment this line to delete
without prompting - don't forget to set to true once done!

totalsheets = ActiveWorkbook.Sheets.Count
While (5 <= totalsheets)
ActiveWorkbook.Sheets(5).Delete
totalsheets = totalsheets - 1
Wend
End Sub



should do you (prompting to delete each sheet first) - make a backup of

your
file before testing this one!

Regards

David


"Todd Huttenstine" wrote in message
...
Hey guys,

What is the code to delete every sheet in the active workbook from
worksheets(4) onward? I want to keep sheets 1-4 but delete the rest.


Thanx

Todd Huttenstine








All times are GMT +1. The time now is 12:00 PM.

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