LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Delete Worksheets Named Sheet1, Sheet2, Sheet3, etc.

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. Im trying to
find a way to delete these few sheets that are created. I just cant 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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple? View named range from sheet1 on sheet2 susiew32 Excel Worksheet Functions 1 August 27th 09 03:29 PM
copy data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Excel Discussion (Misc queries) 6 February 27th 09 09:48 PM
A1 in sheet1 =” =SUM('sheet2:sheet3'!A1)” minrufeng[_12_] Excel Programming 1 February 22nd 06 07:02 PM
consoildate all the worksheet(example sheet1,sheet2 and sheet3 etc officeboy Excel Worksheet Functions 1 November 4th 04 04:16 PM
copy data from sheet1 based on criteria in sheet2 to sheet3 Fred Excel Programming 3 May 25th 04 01:46 PM


All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"