lynnnow
05-16-2010, 11:16 PM
Hi,
Please help me with this:
I've got a workbook that is created with a default of 3 sheets. I add one more sheet from another workbook, making the total count of sheets to 4. The sheets are named "Day", "Month", "Sheet2" and "Sheet3".
I've written this code to delete the sheets named "Sheet" leaving just the "Day" and "Month" sheets in the WB.
Application.DisplayAlerts = False
For j = 1 To ActiveWorkbook.Sheets.Count
If Left(Sheets(j).Name, 5) = "Sheet" Then
Sheets(j).Delete
End If
Next
Application.DisplayAlerts = True
My query is that the for loop increments to 4 and then there is an out of subscript error. I want the for loop to quit after all sheets name "Sheetx" are deleted.
Please advise:dunno.
Lincoln
Please help me with this:
I've got a workbook that is created with a default of 3 sheets. I add one more sheet from another workbook, making the total count of sheets to 4. The sheets are named "Day", "Month", "Sheet2" and "Sheet3".
I've written this code to delete the sheets named "Sheet" leaving just the "Day" and "Month" sheets in the WB.
Application.DisplayAlerts = False
For j = 1 To ActiveWorkbook.Sheets.Count
If Left(Sheets(j).Name, 5) = "Sheet" Then
Sheets(j).Delete
End If
Next
Application.DisplayAlerts = True
My query is that the for loop increments to 4 and then there is an out of subscript error. I want the for loop to quit after all sheets name "Sheetx" are deleted.
Please advise:dunno.
Lincoln