LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Check for Existance of sheet - problem with UDF

Hi,

I'm using a udf to test for the existance of a worksheet and to perform an
action if the sheet is found. The code for the function is as follows:


Function WksExists(ByVal wksName As String) As Boolean
WksExists = CBool(Len(Worksheets(wksName).Name) 0)
End Function


In my procedure I call the function using:


If WksExists("1 (2)") = True Then ' Test for existance of sheet
Sheets("1 (2)").Select ' If true then select sheet
Sheets("1 (2)").Name = i + 1 ' Rename sheet with the value of i
+1
End If


This works fine if the sheet "1 (2)" actually does exist. The probelm is if
the sheet "1 (2)" doesn't exist I get a "Run-Time Error 9" - "Subscript out
of Range".

Any idea why this is happening and how I would over come it.

Thanks in advance

...pc


 
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
Check Activesheet for chart sheet or work sheet NSK Charts and Charting in Excel 1 July 17th 07 09:00 PM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM
How to check for the existance of a Sheet (or not) Pete[_22_] Excel Programming 2 April 5th 05 04:27 PM
error handling - check chart existance annette2002[_2_] Excel Programming 1 June 9th 04 06:03 AM
Existance Check Fails ChuckM[_2_] Excel Programming 7 January 31st 04 03:02 AM


All times are GMT +1. The time now is 12:01 AM.

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

About Us

"It's about Microsoft Excel"