Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
swiftcode
 
Posts: n/a
Default 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   Report Post  
JMB
 
Posts: n/a
Default

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   Report Post  
swiftcode
 
Posts: n/a
Default

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   Report Post  
JMB
 
Posts: n/a
Default

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
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



All times are GMT +1. The time now is 01:27 PM.

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"