Macro to deleting spreadsheets in a workbook

S

Snoopy

Hey guys
My macro uses a pivottablefunction (zoom value) to extract data. This
pivot-function creates a new sheet in my workbook, and I'm looking for
a methode to make my macro delete this new sheet in the end of the
program, when the extract is copied, placed (pasted) and formatted in
right position.
The problem (my problem) is that the new sheets are automaticly
generated by Excel with new index every time the zoomvalue function is
activated - so I have to make my macro delete all sheets that is named
"sheetxx" (xx is index) - and spare the other ones.

This is certainly a small step to life of Excel-VBA-mankind, but a big
step to make my day :)))


With hopefully regards
Snoopy
 
T

Tom Ogilvy

Dim s as String, sh as Worksheet
Application.DisplayAlerts = False
for each sh in worksheets
s = lcase(sh.name)
if len(s) > 5 then
if left(s,5) = "sheet" then
sh.Delete
end if
end if
Next
Application.DisplayAlerts = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top