Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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

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
delete value on worksheet 2 that match values on worksheet 1 np Excel Discussion (Misc queries) 0 December 10th 09 06:02 PM
How to delete chart NonTechie Charts and Charting in Excel 7 September 24th 09 05:59 AM
delete chart Wayne Excel Discussion (Misc queries) 6 May 3rd 07 03:00 PM
How to delete a duplicate Excel worksheet within that worksheet? jozawun Excel Discussion (Misc queries) 6 September 19th 06 02:20 PM
Using VBA to Delete a Chart MikeM[_2_] Excel Programming 3 October 14th 03 02:49 AM


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