Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If sheet1 exists then delete, if not End If 1

Status
Not open for further replies.

JamieArvato

Technical User
Aug 5, 2004
50
GB
How do I write code to say if there is a sheet1 in the workbook then delete if not then end if.

thanks
 
Something like this?

[tt]dim sh as worksheet
application.displayalerts=false
for each sh in thisworkbook.worksheets
if ucase(sh.name) = "SHEET1" then
sh.delete
end if
next sh
application.displayalerts=true[/tt]

Roy-Vidar
 
As a side note, this wont work if there is only 1 sheet in the workbook.
 
Another way to skin this particular cat is
Code:
Application.DisplayAlerts = False
On Error Resume Next
Worksheets("sheet1").Delete
On Error GoTo 0
Application.DisplayAlerts = True

Molby's comment is still relevant here!

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top