Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Linking existing wookbooks and updating graphs | Excel Discussion (Misc queries) | |||
Excel Deleting embedded graphs during worksheet copy | Charts and Charting in Excel | |||
Formatting worksheets, existing and new, in existing workbooks | Excel Discussion (Misc queries) | |||
download existing spreadsheets into another existing spreadsheet | Excel Discussion (Misc queries) | |||
moving data in excel without deleting existing data | Excel Discussion (Misc queries) |