ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How2 Delete "Not exist" charts/sheets? (https://www.excelbanter.com/excel-programming/304704-how2-delete-not-exist-charts-sheets.html)

fatfish[_4_]

How2 Delete "Not exist" charts/sheets?
 
Hi all,

I created the macro to delete charts..
Also I add a button to the menu and wanna click the button
to delete all the used charts.

The problem is: I wanna use one button to "clean" ALL the "used
charts,
but some of those charts may not exist (because I use different macr
to
create different charts), so Excel can not find them and will ask me t
debug.
e.g.
Sheets("Chart TC123").Select
ActiveWindow.SelectedSheets.Delete

and "Chart TC123" doesn't exist!
How to avoid the error message

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

How2 Delete "Not exist" charts/sheets?
 
On Error Resume Next
Sheets("Chart TC123").Select
ActiveWindow.SelectedSheets.Delete
On Error goto 0

--
Regards,
Tom Ogilvy

"fatfish " wrote in message
...
Hi all,

I created the macro to delete charts..
Also I add a button to the menu and wanna click the button
to delete all the used charts.

The problem is: I wanna use one button to "clean" ALL the "used"
charts,
but some of those charts may not exist (because I use different macro
to
create different charts), so Excel can not find them and will ask me to
debug.
e.g.
Sheets("Chart TC123").Select
ActiveWindow.SelectedSheets.Delete

and "Chart TC123" doesn't exist!
How to avoid the error message?


---
Message posted from http://www.ExcelForum.com/




Amedee Van Gasse[_3_]

How2 Delete "Not exist" charts/sheets?
 
fatfish wrote:

Hi all,

I created the macro to delete charts..
Also I add a button to the menu and wanna click the button
to delete all the used charts.

The problem is: I wanna use one button to "clean" ALL the "used"
charts,
but some of those charts may not exist (because I use different macro
to
create different charts), so Excel can not find them and will ask me
to debug.
e.g.
Sheets("Chart TC123").Select
ActiveWindow.SelectedSheets.Delete

and "Chart TC123" doesn't exist!
How to avoid the error message?


You could use something like this:

Sub DeleteMySheet(MySheetName As String)
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
If sh.Name = MySheetName Then sh.Delete
Next sh
End Sub


--
To top-post is human, to bottom-post and snip is sublime.

fatfish[_6_]

How2 Delete "Not exist" charts/sheets?
 
Today is my lucky day:)

Thanks to Tom for your very simple and effective answer!
Thanks again to Amedee for your very logical solution! ;

--
Message posted from http://www.ExcelForum.com


fatfish[_5_]

How2 Delete "Not exist" charts/sheets?
 
Today is my lucky day:)

Thanks to Tom for your very simple and effective answer!
Thanks again to Amedee for your very logical solution! ;

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:23 PM.

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