Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Test to see if a worksheet exists thanks, Chip

Thanks, Chip
Chip Pearson wrote in message
...
Try something like the following;

Function WorksheetExists(SheetName As String, _
Optional WhichBook As Workbook) As Boolean
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = Len(WB.Worksheets(SheetName).Name) 0
End Function

You can then call this function in code as follows:

If WorksheetExists("Sheet123") = True Then
' sheet exists
Else
' sheet does not exist
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"CT" wrote in message
ink.net...
Sometimes when I try to add a new sheet ...
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Input"
I fail because there is already a worksheet named "Input".

So, before adding the new sheet, I do ...
For Each MyWorksheet In Worksheets
If MyWorksheet.Name = "Input" Then
Application.DisplayAlerts = False
Worksheets("Input").Delete
Application.DisplayAlerts = True
End If
Next MyWorksheet

Is there a more simple way to check to see if the "Input" sheet

exists?






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
Test if file exists Daniel Bonallack Excel Discussion (Misc queries) 2 May 4th 09 04:19 PM
check if worksheet exists joeeng Excel Worksheet Functions 3 September 7th 05 06:49 PM
If Worksheets("Test") Exists Then Delete It Don[_7_] Excel Programming 0 July 22nd 03 12:09 PM
easy way to test if a Named Range exists Andrew Bauer Excel Programming 4 July 10th 03 07:32 PM
check if worksheet exists Craig Wilks Excel Programming 2 July 10th 03 04:07 AM


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