View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_5_] Jim Thomlinson[_5_] is offline
external usenet poster
 
Posts: 486
Default Error Trapping Question

Try something like this...

Sub DeleteSheet()
if sheetexists("Sheet1") then Sheets("Sheet1").Delete
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

I have this simple macro

Sub DeleteSheet()
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
End Sub

How should I modify it so that if Sheet1 isn't present, it'll just move on.
I'll want to add more to this at a later time, so Exit Sub may not
necessarily be an option.