How can I programmatically check in Excel 2002 if a sheet exists?

G

Guest

from within the workbook, using VB, I need check all of the worksheet names
to see if a name exists - listnames method(?) pastes them to a cell but I
need to check within the list to see if it exists. Thanks.
 
B

Bob Phillips

Here is a function

'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
G

Guest

Works like a charm - thanks very much Bob!
-tom

Bob Phillips said:
Here is a function

'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top