LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default If Sheet Exist

Yet another way


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

(replace somewhere in email address with gmail if mailing direct)

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i think this is a similar way

Sub wsexist()
On Error Resume Next
Worksheets("data").Activate
If Worksheets("data") Is Nothing Then
MsgBox "sheet does not exist"
Else
MsgBox "sheet exists"
End If

End Sub

--


Gary


"Peter" wrote in message
...
Hi,

I'm trying to write a macro that performs a check on whether a Sheet

Exists
or not.

If the Sheet named "Data" Exists the user should be prompted for

accepting
the Sheet to be deleted.
If not the Sheet should be added to the Excel Workbook. The last part is
easy but checking if the Sheet exists is troublesome. I have tried the
Object.Exists(Key) but recieves an error.

I could probably use the Worksheets("Data").Delete command to simply

delete
the Sheet "Data" and then continue adding the Sheet.

But then I would need to drop the Add.Sheet procedure if the user do not
accept that the Sheet gets deleted.

Could anyone help me out here







 
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
Verify if sheet name still exist Edmund Excel Programming 9 July 11th 06 05:08 PM
VBA, Make a new sheet if it doesn't exist PaulW Excel Discussion (Misc queries) 1 May 5th 06 05:25 PM
error when sheet doesn't exist... Ctech[_38_] Excel Programming 10 November 11th 05 01:08 PM
Does the sheet exist? Dr.Schwartz Excel Programming 1 August 25th 04 02:16 PM
Does sheet exist? Sean Evanovich Excel Programming 2 November 19th 03 02:30 PM


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

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"