Searching Sheet Names

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a function that determines if a particular string is the name of a sheet in a workbook? Something like
x = ISSHEET(MyString

where x is T/F or the sheet index number. I can do the search using the following code

For Each Sh in ThisWorkbook.Sheet
If MyString = Sh.Name Then ..

but I need this function to be called millions of times, so if there is a quicker way to accomplish this it would help greatly

Randal
 
Hi Randall,

Here is my function

Function IsWsSheet(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
Set oWs = wb.Worksheets(sh)
On Error GoTo 0
IsWsSheet = Not oWs Is Nothing

End Function


It caters for other workbooks, but defaults tgo the active workbook.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Randall B said:
Is there a function that determines if a particular string is the name of
a sheet in a workbook? Something like
x = ISSHEET(MyString)

where x is T/F or the sheet index number. I can do the search using the following code:

For Each Sh in ThisWorkbook.Sheets
If MyString = Sh.Name Then ...

but I need this function to be called millions of times, so if there is a
quicker way to accomplish this it would help greatly.
 

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

Back
Top