Deleting every sheet in workbook after Worksheets(4)

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

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
 
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
 
Thank you

Todd


David Coleman said:
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
 
Back
Top