Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How can I know if a sheet exists ?

Hi,
My first question is exactly the title : How can I know if a sheet exists ?
And My second question is: how can I delete a sheet without having the message from excel : "are you sure you want to delete...blablabla..... click OK to delete it".
Thanks a lot for âny help and have a hppy new year.
Benjamin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How can I know if a sheet exists ?

Hi Ben

Try this, copy the function and sub in a normal module

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

Sub Sheet_Test()
Dim SName As String
If SheetExists("test") = False Then
MsgBox "don't exist"
Else
MsgBox "sheet exist"
End If
End Sub


For deleting the sheet you can use this

Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Ben.C" wrote in message ...
Hi,
My first question is exactly the title : How can I know if a sheet exists ?
And My second question is: how can I delete a sheet without having the message from excel : "are you sure you want to

delete...blablabla..... click OK to delete it".
Thanks a lot for ny help and have a hppy new year.
Benjamin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How can I know if a sheet exists ?

You can delete this line Ben

Dim SName As String

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Ron de Bruin" wrote in message ...
Hi Ben

Try this, copy the function and sub in a normal module

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

Sub Sheet_Test()
Dim SName As String
If SheetExists("test") = False Then
MsgBox "don't exist"
Else
MsgBox "sheet exist"
End If
End Sub


For deleting the sheet you can use this

Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Ben.C" wrote in message ...
Hi,
My first question is exactly the title : How can I know if a sheet exists ?
And My second question is: how can I delete a sheet without having the message from excel : "are you sure you want to

delete...blablabla..... click OK to delete it".
Thanks a lot for ny help and have a hppy new year.
Benjamin





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How can I know if a sheet exists ?

Thanks a lot Ron !!!!!
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
How to check to see if a sheet with a particular name exists? Varun Excel Worksheet Functions 3 January 25th 09 01:41 PM
check if the sheet/tag exists Alex Excel Worksheet Functions 2 March 14th 06 08:58 PM
Sheet name already exists eddie_zoom Excel Discussion (Misc queries) 1 March 11th 05 02:53 PM
Testing to see if a sheet name exists anita Excel Programming 1 September 4th 03 10:14 PM
check if sheet exists Ross[_6_] Excel Programming 3 July 25th 03 06:46 PM


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