Yes, I have several other sheets in the workbook. I am trying to delete only
two or three that come in at the end of the loop. These irrelevant sheets
are always named Sheet1, Sheet2, etc. Sometimes Sheet18, Sheet19, etc. will
be crated if I run the loop several times before closing the workbook.
--
RyGuy
"Susan" wrote:
> i assume you have other worksheets in the workbook that AREN'T named
> sheet*???
> because you can't delete all the worksheets in a workbook.
> you have to have at least one there, and at least one visible.
> hth
> susan
>
>
> On Apr 6, 2:52 pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
> wrote:
> > Some great people helped me out with code similar to that posted below. I
> > used a slightly modified version of this code to delete a few specific
> > sheets, and I am now trying to modify it to delete any sheet named Sheet1,
> > Sheet2, Sheet3, etc. Basically, I have code that loops and builds a workbook
> > with many sheets that contain information about stocks. Sometimes the loop
> > spits out sheets named Sheet1, Sheet2, etc. and then it ends. I'm trying to
> > find a way to delete these few sheets that are created. I just can't figure
> > out why the samples of code below will not delete the superfluous sheets.
> > Does VBA support the * character?
> >
> > Sub DelSheets()
> >
> > For Each ws In Worksheets
> > If ws.Name = "Sheet*" Then ws.Delete
> > Next ws
> >
> > For Each ws In Workbooks
> > If ws.Name Like "Sheet*" Then ws.Delete
> > Next ws
> >
> > For Each sh In ActiveWorkbook.Worksheets
> > If InStr(1, sh.Name, "Sheet*") Then
> > sh.Delete
> > End If
> > Next sh
> >
> > End Sub
> >
> > --
> > RyGuy
>
>
>
|