ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete worksheet with chart? (https://www.excelbanter.com/excel-programming/337988-delete-worksheet-chart.html)

Judy Ward

delete worksheet with chart?
 
I have a macro that is supposed to delete a sheet from the active workbook:
Sub RemoveSheet()
Dim sh As Object

On Error Resume Next
Set sh = Worksheets("Summary")
On Error GoTo 0
If Not sh Is Nothing Then
sh.Delete
End If
End Sub

The sheet is not deleted. I have double-checked the name of the sheet using:
MsgBox "Sheet name is: x" & ActiveSheet.Name & "x"
There are no leading or trailing spaces. Does it matter that this sheet is
a chart?

I would appreciate any help you can give me with checking to see if a sheet
exists before trying to delete it.

Thank you,
Judy

Andy Pope

delete worksheet with chart?
 
Hi,

If it's a chartsheet it will make all the difference as you are using
Worksheets() to return a reference.
try this instead should work if sheet is a work or chart sheet.

Sub RemoveSheet()
Dim sh As Object

On Error Resume Next
Set sh = Sheets("Summary")
On Error GoTo 0
If Not sh Is Nothing Then
sh.Delete
End If
End Sub

Cheers
Andy

Judy Ward wrote:
I have a macro that is supposed to delete a sheet from the active workbook:
Sub RemoveSheet()
Dim sh As Object

On Error Resume Next
Set sh = Worksheets("Summary")
On Error GoTo 0
If Not sh Is Nothing Then
sh.Delete
End If
End Sub

The sheet is not deleted. I have double-checked the name of the sheet using:
MsgBox "Sheet name is: x" & ActiveSheet.Name & "x"
There are no leading or trailing spaces. Does it matter that this sheet is
a chart?

I would appreciate any help you can give me with checking to see if a sheet
exists before trying to delete it.

Thank you,
Judy


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Judy Ward

delete worksheet with chart?
 
Thank you very much--that was what I needed to know!

"Andy Pope" wrote:

Hi,

If it's a chartsheet it will make all the difference as you are using
Worksheets() to return a reference.
try this instead should work if sheet is a work or chart sheet.

Sub RemoveSheet()
Dim sh As Object

On Error Resume Next
Set sh = Sheets("Summary")
On Error GoTo 0
If Not sh Is Nothing Then
sh.Delete
End If
End Sub

Cheers
Andy

Judy Ward wrote:
I have a macro that is supposed to delete a sheet from the active workbook:
Sub RemoveSheet()
Dim sh As Object

On Error Resume Next
Set sh = Worksheets("Summary")
On Error GoTo 0
If Not sh Is Nothing Then
sh.Delete
End If
End Sub

The sheet is not deleted. I have double-checked the name of the sheet using:
MsgBox "Sheet name is: x" & ActiveSheet.Name & "x"
There are no leading or trailing spaces. Does it matter that this sheet is
a chart?

I would appreciate any help you can give me with checking to see if a sheet
exists before trying to delete it.

Thank you,
Judy


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com