+ Reply to Thread
Results 1 to 2 of 2

How do I write an 'if exist" statement

  1. #1
    John in Surrey
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1