Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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". |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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". |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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". |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If statement linking data from one sheet to another | Excel Worksheet Functions | |||
If statement linking data from one sheet to another | Excel Worksheet Functions | |||
copy cells from multiple pages to one sheet w/ if statement | Excel Worksheet Functions | |||
How to use cell fron different sheet in IF statement | Excel Discussion (Misc queries) | |||
dates and if statement work on one sheet, not on another | Excel Worksheet Functions |