Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How do I check if a sheetname exists in a file?

Hello experts, I am a real novice so be patient please. I want to create a
script that allows me to check whether a particular worksheet exists in a
workbook. At the moment my script assumes 'sheet 1' exists:

[Sheets("Sheet 1").Delete]

However, if the sheet has been manually deleted by the user my macro crashes.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How do I check if a sheetname exists in a file?

Here's one way:
Dim WS As Worksheet
On Error resume Next
Set WS=Thisworkbook.Sheets("Sheet 1")
'You may want an Application.displayalerts=false/true
If Not WS is Nothing then WS.delete
On error goto 0

NickHK

"NezRhodes" wrote in message
...
Hello experts, I am a real novice so be patient please. I want to create a
script that allows me to check whether a particular worksheet exists in a
workbook. At the moment my script assumes 'sheet 1' exists:

[Sheets("Sheet 1").Delete]

However, if the sheet has been manually deleted by the user my macro

crashes.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How do I check if a sheetname exists in a file?

Thanks Nick, it is perfect & much appreciated

"NickHK" wrote:

Here's one way:
Dim WS As Worksheet
On Error resume Next
Set WS=Thisworkbook.Sheets("Sheet 1")
'You may want an Application.displayalerts=false/true
If Not WS is Nothing then WS.delete
On error goto 0

NickHK

"NezRhodes" wrote in message
...
Hello experts, I am a real novice so be patient please. I want to create a
script that allows me to check whether a particular worksheet exists in a
workbook. At the moment my script assumes 'sheet 1' exists:

[Sheets("Sheet 1").Delete]

However, if the sheet has been manually deleted by the user my macro

crashes.



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
Check if file exists Jon Excel Discussion (Misc queries) 14 October 4th 07 04:57 PM
How to check if a file exists in an ftp folder LL Cool A Excel Discussion (Misc queries) 3 May 16th 06 09:22 PM
check if file exists Curt Excel Programming 0 December 7th 05 05:02 PM
How check for No/Cancel Button when SaveAs and file already exists? Joe HM Excel Programming 7 April 19th 05 10:53 AM
check if a file exists / is open Mark Kubicki Excel Programming 1 December 4th 03 05:56 PM


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