Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
John in Surrey
 
Posts: n/a
Default How do I write an 'if exist" statement


Hi folks
My macro copys a sheet (template) and renames it by todays date
Sheets("Template (2)").Select
Sheets("Template (2)").Name = sName

How do I write:
if exist a sheet by the name sName
cancel the process , delete Template 2
else
Sheets("Template (2)").Select
Sheets("Template (2)").Name = sName
endif

thanks
JKohn
john
Images of home (NZ)
http:\\www.myplace.co.nz/home
What we are up to in the UK
http:\\www.myplace.co.nz
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default How do I write an 'if exist" 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
(remove nothere from the email address if mailing direct)


"John in Surrey" wrote in message
...

Hi folks
My macro copys a sheet (template) and renames it by todays date
Sheets("Template (2)").Select
Sheets("Template (2)").Name = sName

How do I write:
if exist a sheet by the name sName
cancel the process , delete Template 2
else
Sheets("Template (2)").Select
Sheets("Template (2)").Name = sName
endif

thanks
JKohn
john
Images of home (NZ)
http:\\www.myplace.co.nz/home
What we are up to in the UK
http:\\www.myplace.co.nz



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
Long IF Statement rmitchell87 Excel Discussion (Misc queries) 2 October 2nd 05 03:50 AM
If statement Matt Montagliano Excel Discussion (Misc queries) 1 September 8th 05 08:47 PM
how do I write the date in an if statement Susan Hayes Excel Worksheet Functions 1 August 23rd 05 09:29 PM
Do I need a sumif or sum of a vlookup formula? PeterB Excel Worksheet Functions 0 June 1st 05 12:23 PM
How do I write a conditional statement in Excel to count if two c. marblelife Excel Worksheet Functions 2 January 16th 05 11:16 PM


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