add sheet if statement
I want to run a certain VBA code if a sheet in a workbook
is present and not if it isn't. If there is a sheet named "Time" I want it to do nothing. If there is no sheet named "Time" I want it to add a sheet and name it "Time". |
add sheet if statement
Function SheetExists(SheetName As String) As Boolean ' returns TRUE if the sheet exists in the active workbook SheetExists = False On Error GoTo NoSuchSheet If Len(Sheets(SheetName).Name) 0 Then SheetExists = True Exit Function End If NoSuchSheet: End Functio -- SCSA2 ----------------------------------------------------------------------- SCSA25's Profile: http://www.excelforum.com/member.php...fo&userid=1510 View this thread: http://www.excelforum.com/showthread.php?threadid=26740 |
add sheet if statement
Try something like
Dim Sht As Worksheet On Error Resume Next Set Sht = ActiveWorkbook.Worksheets("Time") On Error Goto 0 If Sht Is Nothing Then Sheets.Add.Name = "Time" End If -- Regards Juan Pablo González "scrabtree" wrote in message ... I want to run a certain VBA code if a sheet in a workbook is present and not if it isn't. If there is a sheet named "Time" I want it to do nothing. If there is no sheet named "Time" I want it to add a sheet and name it "Time". |
add sheet if statement
'-----------------------------------------------------------------
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 RP "scrabtree" wrote in message ... I want to run a certain VBA code if a sheet in a workbook is present and not if it isn't. If there is a sheet named "Time" I want it to do nothing. If there is no sheet named "Time" I want it to add a sheet and name it "Time". |
All times are GMT +1. The time now is 08:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com