G
Guest
I need to conditionally delete certain sheets based on name. Here's my code:
Dim mWorksheet As Worksheet
'Process worksheets
For Each mWorksheet In Worksheets
mWorksheet.Select
'Application.DisplayAlerts = False
If mWorksheet.Name = "Milestone Summary" Then mWorksheet.Delete
If mWorksheet.Name = "Columns Template" Then mWorksheet.Delete
'Application.DisplayAlerts = True
If WorksheetType(mWorksheet) = "Status" Then ProcessWorkSheet
Next mWorksheet
I get a non-descript application error on the deletions, I think because
when I delete a particular worksheet it changes the number of worksheets in
the Worksheets collection, which screws up the counting process.
Is there an easy alternative? Or, do I need to go through the collection
first remembering the sheet names I need to later delete?
Dim mWorksheet As Worksheet
'Process worksheets
For Each mWorksheet In Worksheets
mWorksheet.Select
'Application.DisplayAlerts = False
If mWorksheet.Name = "Milestone Summary" Then mWorksheet.Delete
If mWorksheet.Name = "Columns Template" Then mWorksheet.Delete
'Application.DisplayAlerts = True
If WorksheetType(mWorksheet) = "Status" Then ProcessWorkSheet
Next mWorksheet
I get a non-descript application error on the deletions, I think because
when I delete a particular worksheet it changes the number of worksheets in
the Worksheets collection, which screws up the counting process.
Is there an easy alternative? Or, do I need to go through the collection
first remembering the sheet names I need to later delete?
