Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deleting graphs (if existing)


Hi.
I want to delete graphsheets automatically if they exists. The code
Sheets("Graph1").Delete will give an error when the graph doesn't
exists. If there is no possible way of doing this, maybe there is a way
to delete all the sheets with the exclusion of a few that i DO want to
keep.
Thanks for your help in advance.


--
MeisterHim
------------------------------------------------------------------------
MeisterHim's Profile: http://www.excelforum.com/member.php...o&userid=27401
View this thread: http://www.excelforum.com/showthread...hreadid=472284

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Deleting graphs (if existing)

Hi MeisterHim.

To delete all chart sheets in a workbook, try:

ActiveWorkbook.Charts.Delete


To delete all sheets except for specified sheets, try something like:

'=================
Public Sub Tester()
Dim SH As Object
Dim arrKeep As Variant

arrKeep = Array("Sheet1", "Sheet5", "Sheet7")

Application.DisplayAlerts = False
For Each SH In ActiveWorkbook.Sheets
If IsError(Application. _
Match(SH.Name, arrKeep, 0)) Then
SH.Delete
End If
Next SH
Application.DisplayAlerts = True

End Sub
'<<=================

Change the names in arrKeep to reflect the sheets to be retained.

---
Regards,
Norman



"MeisterHim" wrote
in message ...

Hi.
I want to delete graphsheets automatically if they exists. The code
Sheets("Graph1").Delete will give an error when the graph doesn't
exists. If there is no possible way of doing this, maybe there is a way
to delete all the sheets with the exclusion of a few that i DO want to
keep.
Thanks for your help in advance.


--
MeisterHim
------------------------------------------------------------------------
MeisterHim's Profile:
http://www.excelforum.com/member.php...o&userid=27401
View this thread: http://www.excelforum.com/showthread...hreadid=472284



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deleting graphs (if existing)


ok now it looks like this:

Public Sub GfkVerw()
Dim SH As Object
Dim arrKeep As Variant

arrKeep = Array("Database 1", "Database 2", "Criteria")

Application.DisplayAlerts = False
For Each SH In ActiveWorkbook.Sheets
If IsError(Application. _
Match(SH.Name, arrKeep, 0)) Then
SH.Delete
End If
Next SH
Application.DisplayAlerts = True

End Sub

i get no error but it doesn't delete any sheets either. altered the
arrKeep array. under the impression that i must alter something else
too (probably something with the SH), but i'm clearly too noobish to
see what exactely. a bit more guidance would be much appreciated.


--
MeisterHim
------------------------------------------------------------------------
MeisterHim's Profile: http://www.excelforum.com/member.php...o&userid=27401
View this thread: http://www.excelforum.com/showthread...hreadid=472284

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Deleting graphs (if existing)

Hi MeisterHim,

I renamed three sheets in a workbook as "Database 1", "Database 2", and
"Criteria" and ran your version of my macro against this workbook.

This resulted in all sheets in the workbook being deleted except for the
renamed sheets: i.e. the macro operated as originally suggested.

Incidentally, since a workbook must contain at least one sheet, the macro
will generate an error if arrKeep does not contain at least one valid sheet
name. This contingancy could, of course, readily be addressed.

---
Regards,
Norman



"MeisterHim" wrote
in message ...

ok now it looks like this:

Public Sub GfkVerw()
Dim SH As Object
Dim arrKeep As Variant

arrKeep = Array("Database 1", "Database 2", "Criteria")

Application.DisplayAlerts = False
For Each SH In ActiveWorkbook.Sheets
If IsError(Application. _
Match(SH.Name, arrKeep, 0)) Then
SH.Delete
End If
Next SH
Application.DisplayAlerts = True

End Sub

i get no error but it doesn't delete any sheets either. altered the
arrKeep array. under the impression that i must alter something else
too (probably something with the SH), but i'm clearly too noobish to
see what exactely. a bit more guidance would be much appreciated.


--
MeisterHim
------------------------------------------------------------------------
MeisterHim's Profile:
http://www.excelforum.com/member.php...o&userid=27401
View this thread: http://www.excelforum.com/showthread...hreadid=472284



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deleting graphs (if existing)


stupid me :P forgot that the other macro makes new sheets again with the
same name. in other words it worked fine all along. hehe. many thanks
for taking the time to help me.


--
MeisterHim
------------------------------------------------------------------------
MeisterHim's Profile: http://www.excelforum.com/member.php...o&userid=27401
View this thread: http://www.excelforum.com/showthread...hreadid=472284



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
Linking existing wookbooks and updating graphs Tatu Excel Discussion (Misc queries) 0 February 27th 09 02:09 PM
Excel Deleting embedded graphs during worksheet copy DaveH Charts and Charting in Excel 2 February 2nd 09 06:13 PM
Formatting worksheets, existing and new, in existing workbooks G. Dagger[_2_] Excel Discussion (Misc queries) 4 January 7th 08 06:48 PM
download existing spreadsheets into another existing spreadsheet lbierer Excel Discussion (Misc queries) 2 September 24th 06 08:36 PM
moving data in excel without deleting existing data jigna Excel Discussion (Misc queries) 1 January 30th 05 11:35 AM


All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"