Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Test if file exists | Excel Discussion (Misc queries) | |||
check if worksheet exists | Excel Worksheet Functions | |||
If Worksheets("Test") Exists Then Delete It | Excel Programming | |||
easy way to test if a Named Range exists | Excel Programming | |||
check if worksheet exists | Excel Programming |