I stole this from Chip Pearson:
Function WorksheetExists(SheetName As Variant, _
Optional WhichBook As Workbook) As Boolean
'from Chip Pearson
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) > 0)
End Function
'and you can use it like:
....
if worksheetexists("myname",activeworkbook) then
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,
--
Dave Peterson
|