Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
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
If statement linking data from one sheet to another Mathew Excel Worksheet Functions 3 May 27th 10 10:49 PM
If statement linking data from one sheet to another Mathew Excel Worksheet Functions 1 May 27th 10 09:44 PM
copy cells from multiple pages to one sheet w/ if statement GHall Excel Worksheet Functions 8 January 15th 09 08:24 PM
How to use cell fron different sheet in IF statement Cyberbiker Excel Discussion (Misc queries) 5 November 14th 07 02:15 PM
dates and if statement work on one sheet, not on another John Brown Excel Worksheet Functions 3 September 8th 05 12:58 AM


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