+ Reply to Thread
Results 1 to 4 of 4

detect and delete existing sheet

  1. #1
    swiftcode
    Guest

    detect and delete existing sheet

    Hi all,

    Could any please advise me how i am able to detect an existing sheetname,
    e.g. "CSV", if it exist then toi delete the sheet, if it doesn't then just
    open a message box to let me know.

    Thanks in advace.

  2. #2
    JMB
    Guest

    RE: detect and delete existing sheet

    Sub DeleteSheet()
    Const SheetName As String = "CSV"
    Dim WkSht As Worksheet

    On Error Resume Next

    Set WkSht = Sheets(SheetName)
    If Err = 0 Then
    Application.DisplayAlerts = False
    WkSht.Delete
    Application.DisplayAlerts = True
    Else
    MsgBox "Sheet does not exist"
    Err.Clear
    End If

    On Error GoTo 0

    End Sub

    "swiftcode" wrote:

    > Hi all,
    >
    > Could any please advise me how i am able to detect an existing sheetname,
    > e.g. "CSV", if it exist then toi delete the sheet, if it doesn't then just
    > open a message box to let me know.
    >
    > Thanks in advace.


  3. #3
    swiftcode
    Guest

    RE: detect and delete existing sheet

    Hi JMB,

    Thank you for your help, this works exactly as i needed.

    Have a good day.

    "JMB" wrote:

    > Sub DeleteSheet()
    > Const SheetName As String = "CSV"
    > Dim WkSht As Worksheet
    >
    > On Error Resume Next
    >
    > Set WkSht = Sheets(SheetName)
    > If Err = 0 Then
    > Application.DisplayAlerts = False
    > WkSht.Delete
    > Application.DisplayAlerts = True
    > Else
    > MsgBox "Sheet does not exist"
    > Err.Clear
    > End If
    >
    > On Error GoTo 0
    >
    > End Sub
    >
    > "swiftcode" wrote:
    >
    > > Hi all,
    > >
    > > Could any please advise me how i am able to detect an existing sheetname,
    > > e.g. "CSV", if it exist then toi delete the sheet, if it doesn't then just
    > > open a message box to let me know.
    > >
    > > Thanks in advace.


  4. #4
    JMB
    Guest

    RE: detect and delete existing sheet

    most welcome.

    "swiftcode" wrote:

    > Hi JMB,
    >
    > Thank you for your help, this works exactly as i needed.
    >
    > Have a good day.
    >
    > "JMB" wrote:
    >
    > > Sub DeleteSheet()
    > > Const SheetName As String = "CSV"
    > > Dim WkSht As Worksheet
    > >
    > > On Error Resume Next
    > >
    > > Set WkSht = Sheets(SheetName)
    > > If Err = 0 Then
    > > Application.DisplayAlerts = False
    > > WkSht.Delete
    > > Application.DisplayAlerts = True
    > > Else
    > > MsgBox "Sheet does not exist"
    > > Err.Clear
    > > End If
    > >
    > > On Error GoTo 0
    > >
    > > End Sub
    > >
    > > "swiftcode" wrote:
    > >
    > > > Hi all,
    > > >
    > > > Could any please advise me how i am able to detect an existing sheetname,
    > > > e.g. "CSV", if it exist then toi delete the sheet, if it doesn't then just
    > > > open a message box to let me know.
    > > >
    > > > Thanks in advace.


+ 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