PDA

View Full Version : [SOLVED:] deleting old ws (cycling sheets)



MINCUS1308
09-30-2014, 07:08 AM
I am trying to accomplish the following:
If I have more than 5 sheets in my workbook, delete the second worksheet.

Example/

if the following list are the ws in my wb:
Template Sep-20 Sep-21 Sep-22 Sep-23 'RESPECTIVE CODENAMES ARE: Sheet1 Sheet17 Sheet18 Sheet19 Sheet20

and I add another ws to the wb (Sep-24):
Template Sep-20 Sep-21 Sep-22 Sep-23 Sep-24 'RESPECTIVE CODENAMES ARE: Sheet1 Sheet17 Sheet18 Sheet19 Sheet20 Sheet21

I want to delete the second ws in the wb (Sep-20) to achieve the following:
Template Sep-21 Sep-22 Sep-23 Sep-24 'RESPECTIVE CODENAMES ARE: Sheet1 Sheet18 Sheet19 Sheet20 Sheet21

Please keep in mind that the ws names are not always linear and that the code names will be cyclical.

Thank you for taking the time to consider this problem.

MINCUS1308
09-30-2014, 07:48 AM
Im stupid. the initial test of my code was failing and i couldnt seem to get it to work.

The following code does what I asked.


Application.DisplayAlerts = False
If (Sheets.Count) > 5 Then
Sheets(2).Select
ActiveSheet.Delete
End If
Application.DisplayAlerts = True


Thanks everyone for humoring me