View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default How do I Test for the existence of a Worksheet from inside a Macro

Sub nosheet()
isthere = False
For Each w In Worksheets
If w.Name = "Sheetxx" Then
isthere = True
End If
Next

If isthere Then
MsgBox ("it's already there")
Else
MsgBox ("It's not there")
End If
End Sub

--
Gary''s Student
gsnu200711


"jb" wrote:

I'm trying to run a macro, but sometimes theres a worksheet in place and
sometimes there isn't. If its not there I need to add it, but if it there
and I try to add it i get an error. Anyone know how to do an if statement
around something like this.

Thanks,