ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How can I programmatically check in Excel 2002 if a sheet exists? (https://www.excelbanter.com/excel-programming/355877-how-can-i-programmatically-check-excel-2002-if-sheet-exists.html)

RangerTom

How can I programmatically check in Excel 2002 if a sheet exists?
 
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.

Bob Phillips[_6_]

How can I programmatically check in Excel 2002 if a sheet exists?
 
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)

"RangerTom" wrote in message
...
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.




RangerTom

How can I programmatically check in Excel 2002 if a sheet exis
 
Works like a charm - thanks very much Bob!
-tom

"Bob Phillips" wrote:

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)

"RangerTom" wrote in message
...
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.






All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com