Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Deleting copies of a spreadsheet

I have a macro that copies a lot sheets, amends them, and deletes the
copied version. Consequently there may be a case for wanting to delete
and sheets that end with '(2)'. Is there a handy piece of code that
would do that and leave all other sheets alone?

Regards,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Deleting copies of a spreadsheet

This is a modified cut and paste, but you could write a little batch file
like

del *2.xls

then call with Shell:

App_ID = Shell("c:\winnt\system32\cmd.exe NoTwos.bat", 3)



"solomon_monkey" wrote in message
oups.com...
I have a macro that copies a lot sheets, amends them, and deletes the
copied version. Consequently there may be a case for wanting to delete
and sheets that end with '(2)'. Is there a handy piece of code that
would do that and leave all other sheets alone?

Regards,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Deleting copies of a spreadsheet

Untested, but here is some code that looks for a sheet with a ( in it, then
checks if a woirksheet with a name equal to the value before the ( exists.

Dim ipos As Long
Dim sh As Worksheet
Dim sh2 As Worksheet

For Each sh In ActiveWorkbook.Worksheets
ipos = InStr(1, sh.Name, "(")
If ipos 0 Then
Set sh2 = Nothing
On Error Resume Next
Set sh2 = Worksheets(Left(sh.Name, ipos - 2))
On Error GoTo 0
If Not sh2 Is Nothing Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
End If
End If
Next sh


--
HTH

Bob Phillips

"solomon_monkey" wrote in message
oups.com...
I have a macro that copies a lot sheets, amends them, and deletes the
copied version. Consequently there may be a case for wanting to delete
and sheets that end with '(2)'. Is there a handy piece of code that
would do that and leave all other sheets alone?

Regards,



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
Deleting copies of past documents PAG Excel Discussion (Misc queries) 1 February 23rd 10 02:52 PM
How do i create upto 50 copies of a spreadsheet within one workboo Paul Excel Worksheet Functions 6 May 8th 09 04:41 PM
Print multiple copies of a spreadsheet on one page JBTjr Excel Discussion (Misc queries) 1 March 3rd 09 10:32 PM
Why when opening a spreadsheet, do two copies appear to open? Pete W Excel Discussion (Misc queries) 3 August 26th 08 06:59 PM
How do I make all copies of a spreadsheet file inoperable? Ed Excel Discussion (Misc queries) 2 October 23rd 05 04:55 AM


All times are GMT +1. The time now is 02:58 AM.

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"