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

Hi-I have an array that before it loops throught the code to create
worksheets i need to determine if the worksheet name already exists.
If it does I want a msgbox to appear then exit the sub. I created the
code below but it does not work. Error:Run time 438 Object doesn't
support this property or method.

If ThisWorkbook.Worksheets(MyArray(i, j)).Exists Then

MsgBox "Cost Centres already exist."
Exit Sub

Else

Please help. Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default If worksheet from array exists then not working

Here is some code to check


'-----------------------------------------------------------------
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

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
ps.com...
Hi-I have an array that before it loops throught the code to create
worksheets i need to determine if the worksheet name already exists.
If it does I want a msgbox to appear then exit the sub. I created the
code below but it does not work. Error:Run time 438 Object doesn't
support this property or method.

If ThisWorkbook.Worksheets(MyArray(i, j)).Exists Then

MsgBox "Cost Centres already exist."
Exit Sub

Else

Please help. Thanks!



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
VLOOK up returning #N/A even though value exists in lookup array [email protected] Excel Worksheet Functions 1 September 4th 07 06:56 PM
Lookup value - see if exists in another array [email protected] Excel Worksheet Functions 1 March 1st 07 03:55 PM
Macro in Excel using an Array to Delete File in Directory if it Exists Matt[_40_] Excel Programming 3 February 2nd 07 03:16 AM
need array of true/false if text exists alex Excel Worksheet Functions 0 November 16th 04 09:58 AM
How to check if a worksheet exists in worksheet collection Raghunandan Excel Programming 2 July 19th 04 06:55 AM


All times are GMT +1. The time now is 06:49 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"