Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default worksheet exists or not


How do I check if a worksheet exists or not before accessing it.


--
skvabbili
------------------------------------------------------------------------
skvabbili's Profile: http://www.excelforum.com/member.php...o&userid=34135
View this thread: http://www.excelforum.com/showthread...hreadid=539068

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default worksheet exists or not

This function will let you know if a sheet exists...

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

Use it like...

if sheetexists("Sheet1") then sheets("Sheet1").Select
--
HTH...

Jim Thomlinson


"skvabbili" wrote:


How do I check if a worksheet exists or not before accessing it.


--
skvabbili
------------------------------------------------------------------------
skvabbili's Profile: http://www.excelforum.com/member.php...o&userid=34135
View this thread: http://www.excelforum.com/showthread...hreadid=539068


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default worksheet exists or not

If SheetExists(sheetname) Then
'


'-----------------------------------------------------------------
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 xxx from email address if mailing direct)

"skvabbili" wrote in
message ...

How do I check if a worksheet exists or not before accessing it.


--
skvabbili
------------------------------------------------------------------------
skvabbili's Profile:

http://www.excelforum.com/member.php...o&userid=34135
View this thread: http://www.excelforum.com/showthread...hreadid=539068



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet exists Kaval Excel Programming 2 February 27th 06 08:49 AM
Check if a worksheet exists Mort_Komabt Excel Programming 4 November 28th 05 12:38 AM
How to check if a worksheet exists in worksheet collection Raghunandan Excel Programming 2 July 19th 04 06:55 AM
Worksheet Exists... James Weaver Excel Programming 3 October 6th 03 02:56 PM
How can I tell if a worksheet exists? Robert Stober Excel Programming 5 October 3rd 03 01:00 AM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"