View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default delete sheet if it exist

Hi Art

You can test it like this with a function

Sub Sheet_Test()
Dim SName As String
If SheetExists("test") = True Then
'code to delete the sheet
Else
'do nothing
End If
End Sub

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


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Art Parra" wrote in message ...
how do I find out if a sheet exist to delete it? I've tried:

if not isnull(sheets("myname")) then
sheets("myname").delete
end if

thanks,