I have a macro that cycles through some data and creates worksheets named with the data. After I have created the sheets I want to delete them and keep the ones named so that it is ready for the next cycle.
The code I have
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Sheets
If wks.Name <> "Data" And wks.Name <> "Summary" And wks.Name <> "Tab1" Then wks.Delete
Next wks
I get the error
run time error 1004
method delete of object worksheet failed
The code I have
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Sheets
If wks.Name <> "Data" And wks.Name <> "Summary" And wks.Name <> "Tab1" Then wks.Delete
Next wks
I get the error
run time error 1004
method delete of object worksheet failed