Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does a worksheet exist?
I am trying to figure out what sort of code I can use in my vba that
would allow it to recognize whether a worksheet with a particular name exists or not. I would like to use it in conjunction with an if-then so that it will do one thing or another dependent on the presence (or lack of) this sheet. TIA |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does a worksheet exist?
Use this 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 RP (remove nothere from the email address if mailing direct) "papa jonah" wrote in message oups.com... I am trying to figure out what sort of code I can use in my vba that would allow it to recognize whether a worksheet with a particular name exists or not. I would like to use it in conjunction with an if-then so that it will do one thing or another dependent on the presence (or lack of) this sheet. TIA |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Does a worksheet exist?
Here is a function...
Public Function SheetExists(SName As String, _ Optional ByVal WB As Workbook) As Boolean 'Chip Pearson On Error Resume Next If WB Is Nothing Then Set WB = ThisWorkbook SheetExists = CBool(Len(WB.Sheets(SName).Name)) End Function -- HTH... Jim Thomlinson "papa jonah" wrote: I am trying to figure out what sort of code I can use in my vba that would allow it to recognize whether a worksheet with a particular name exists or not. I would like to use it in conjunction with an if-then so that it will do one thing or another dependent on the presence (or lack of) this sheet. TIA |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Does worksheet exist | Excel Discussion (Misc queries) | |||
Does Worksheet Exist | Excel Discussion (Misc queries) | |||
Does a worksheet exist | Excel Programming | |||
Does worksheet exist | Excel Programming | |||
check if a worksheet exist - VBA | Excel Programming |