PC Review


Reply
Thread Tools Rate Thread

How to check if a sheet exists ?

 
 
Luc
Guest
Posts: n/a
 
      19th Dec 2009
Title says it all.
Luc
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      19th Dec 2009
Courtexy Chip Pearson:

Function SheetExists(SheetName As String, _
Optional WB As Workbook) As Boolean
Dim W As Workbook
If WB Is Nothing Then
Set W = ActiveWorkbook
Else
Set W = WB
End If
On Error Resume Next
SheetExists = CBool(Len(W.Worksheets(SheetName).Name))
End Function




"Luc" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Title says it all.
Luc
 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      19th Dec 2009
Hi,

I'd have a seperate fumction and call it to test for the existance of a sheet

Sub nn()
MsgBox SheetThere("sheet3")
End Sub


Function SheetThere(ShtName As String) As Boolean
Dim x
On Error GoTo GetMeOut
x = ActiveWorkbook.Sheets(ShtName).Name
SheetThere = True
Exit Function

GetMeOut:
SheetThere = False
End Function


Mike

"Luc" wrote:

> Title says it all.
> Luc

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      19th Dec 2009
Here is a shorter version of your "on error" method for this function...

Function SheetThere(ShtName As String) As Boolean
On Error Resume Next
SheetThere = Len(ActiveWorkbook.Sheets(ShtName).Name)
End Function

--
Rick (MVP - Excel)


"Mike H" <(E-Mail Removed)> wrote in message
news:AFE4BDBD-05FB-4BAF-B991-(E-Mail Removed)...
> Hi,
>
> I'd have a seperate fumction and call it to test for the existance of a
> sheet
>
> Sub nn()
> MsgBox SheetThere("sheet3")
> End Sub
>
>
> Function SheetThere(ShtName As String) As Boolean
> Dim x
> On Error GoTo GetMeOut
> x = ActiveWorkbook.Sheets(ShtName).Name
> SheetThere = True
> Exit Function
>
> GetMeOut:
> SheetThere = False
> End Function
>
>
> Mike
>
> "Luc" wrote:
>
>> Title says it all.
>> Luc


 
Reply With Quote
 
Vivek Samapra
Guest
Posts: n/a
 
      28th Dec 2010
Dude ! ! ! ! I LOVE YOU ! ! ! ! I Have searched over the internet for 3 hours.. Only yours worked the best.. Im going to share this to everyone..

> On Saturday, December 19, 2009 9:16 AM Luc wrote:


> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0049_01CA80BE.43826100
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> Title says it all.
> Luc
> ------=_NextPart_000_0049_01CA80BE.43826100
> Content-Type: text/html;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META content=3D"text/html; charset=3Diso-8859-1" =
> http-equiv=3DContent-Type>
> <META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18865">
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=3D#ffffff>
> <DIV><FONT size=3D2 face=3DArial>Title says it all.</FONT></DIV>
> <DIV><FONT size=3D2 face=3DArial>Luc</FONT></DIV></BODY></HTML>
>
> ------=_NextPart_000_0049_01CA80BE.43826100--



>> On Saturday, December 19, 2009 9:41 AM JLGWhiz wrote:


>> This is a multi-part message in MIME format.
>>
>> ------=_NextPart_000_0008_01CA808F.6957F090
>> Content-Type: text/plain;
>> charset="iso-8859-1"
>> Content-Transfer-Encoding: quoted-printable
>>
>> Courtexy Chip Pearson:
>>
>> Function SheetExists(SheetName As String, _
>> Optional WB As Workbook) As Boolean
>> Dim W As Workbook
>> If WB Is Nothing Then
>> Set W =3D ActiveWorkbook
>> Else
>> Set W =3D WB
>> End If
>> On Error Resume Next
>> SheetExists =3D CBool(Len(W.Worksheets(SheetName).Name))
>> End Function
>>
>>
>>
>>
>> Title says it all.
>> Luc
>> ------=_NextPart_000_0008_01CA808F.6957F090
>> Content-Type: text/html;
>> charset="iso-8859-1"
>> Content-Transfer-Encoding: quoted-printable
>>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>> <HTML><HEAD>
>> <META content=3D"text/html; charset=3Diso-8859-1" =
>> http-equiv=3DContent-Type>
>> <META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18854">
>> <STYLE></STYLE>
>> </HEAD>
>> <BODY bgColor=3D#ffffff>
>> <DIV><FONT size=3D2 face=3DArial>Courtexy Chip Pearson:</FONT></DIV>
>> <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
>> <DIV>Function SheetExists(SheetName As String, _<BR>&nbsp; &nbsp; =
>> Optional WB As=20
>> Workbook) As Boolean<BR>&nbsp; &nbsp; Dim W As Workbook<BR>&nbsp; &nbsp; =
>> If WB=20
>> Is Nothing Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; Set W =3D =
>> ActiveWorkbook<BR>&nbsp;=20
>> &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; Set W =3D WB<BR>&nbsp; &nbsp; =
>> End=20
>> If<BR>&nbsp; &nbsp; On Error Resume Next<BR>&nbsp; &nbsp; SheetExists =
>> =3D=20
>> CBool(Len(W.Worksheets(SheetName).Name))<BR>End Function<BR></DIV>
>> <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
>> <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
>> <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
>> <BLOCKQUOTE=20
>> style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; =
>> PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
>> dir=3Dltr>
>> <DIV>"Luc" &lt;<A href=3D"private.php?do=newpm&u=">(E-Mail Removed)</A>&gt; =
>> wrote in=20
>> message <A=20
>> =
>> <DIV><FONT size=3D2 face=3DArial>Title says it all.</FONT></DIV>
>> <DIV><FONT size=3D2 =
>> face=3DArial>Luc</FONT></DIV></BLOCKQUOTE></BODY></HTML>
>>
>> ------=_NextPart_000_0008_01CA808F.6957F090--



>>> On Saturday, December 19, 2009 10:08 AM Mike H wrote:


>>> Hi,
>>>
>>> I'd have a seperate fumction and call it to test for the existance of a sheet
>>>
>>> Sub nn()
>>> MsgBox SheetThere("sheet3")
>>> End Sub
>>>
>>>
>>> Function SheetThere(ShtName As String) As Boolean
>>> Dim x
>>> On Error GoTo GetMeOut
>>> x = ActiveWorkbook.Sheets(ShtName).Name
>>> SheetThere = True
>>> Exit Function
>>>
>>> GetMeOut:
>>> SheetThere = False
>>> End Function
>>>
>>>
>>> Mike
>>>
>>> "Luc" wrote:



>>>> On Saturday, December 19, 2009 10:22 AM Rick Rothstein wrote:


>>>> Here is a shorter version of your "on error" method for this function...
>>>>
>>>> Function SheetThere(ShtName As String) As Boolean
>>>> On Error Resume Next
>>>> SheetThere = Len(ActiveWorkbook.Sheets(ShtName).Name)
>>>> End Function
>>>>
>>>> --
>>>> Rick (MVP - Excel)



>>>> Submitted via EggHeadCafe
>>>> Microsoft Silverlight For Beginners
>>>> http://www.eggheadcafe.com/training-...lverlight.aspx

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check to see if a sheet with a particular name exists? Varun Microsoft Excel Worksheet Functions 3 25th Jan 2009 01:41 PM
How to check from VBA if sheet exists? Alen Microsoft Excel Programming 2 2nd Mar 2006 12:36 PM
check to see if sheet exists Wandering Mage Microsoft Excel Programming 1 28th Sep 2004 07:53 PM
Check if a sheet exists Jon Microsoft Excel Misc 4 6th May 2004 08:44 AM
check if sheet exists Ross Microsoft Excel Programming 3 25th Jul 2003 06:46 PM


Features
 

Advertising
 

Newsgroups
 


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