ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting copies of a spreadsheet (https://www.excelbanter.com/excel-programming/333548-deleting-copies-spreadsheet.html)

solomon_monkey[_2_]

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,


Kurt[_7_]

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,




Bob Phillips[_7_]

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,





All times are GMT +1. The time now is 09:00 AM.

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