Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Delete all sheets in workbook that contain "Dump" in the name

Hello,

I have a workbook that generally contains 15-18 worksheets. Is it possible
to automate the deletion of only the worksheets with a name that contains the
word "Dump". The amount of worksheets that contain the word "Dump" ranges
from 3-7.

Thanks,

Patrick

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...tions/201005/1

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Delete all sheets in workbook that contain "Dump" in the name

You could use a macro:

Option Explicit
Sub testme()

Dim sh As Object 'could be any kind of sheet
Dim HowManyDeleted As Long

HowManyDeleted = 0
For Each sh In ActiveWorkbook.Sheets
If LCase(sh.Name) Like LCase("*dump*") Then
Application.DisplayAlerts = False 'no "Are you sure" prompt
On Error Resume Next
sh.Delete
If Err.Number < 0 Then
'it failed
Err.Clear
MsgBox "Sheet: " & sh.Name & " was not deleted!"
Else
HowManyDeleted = HowManyDeleted + 1
End If
On Error GoTo 0
Application.DisplayAlerts = True
End If
Next sh

MsgBox "Deleted: " & HowManyDeleted & " sheet(s)."

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

"Porr via OfficeKB.com" wrote:

Hello,

I have a workbook that generally contains 15-18 worksheets. Is it possible
to automate the deletion of only the worksheets with a name that contains the
word "Dump". The amount of worksheets that contain the word "Dump" ranges
from 3-7.

Thanks,

Patrick

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...tions/201005/1


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Delete all sheets in workbook that contain "Dump" in the name

Worked great, I apprecaite it!

Dave Peterson wrote:
You could use a macro:

Option Explicit
Sub testme()

Dim sh As Object 'could be any kind of sheet
Dim HowManyDeleted As Long

HowManyDeleted = 0
For Each sh In ActiveWorkbook.Sheets
If LCase(sh.Name) Like LCase("*dump*") Then
Application.DisplayAlerts = False 'no "Are you sure" prompt
On Error Resume Next
sh.Delete
If Err.Number < 0 Then
'it failed
Err.Clear
MsgBox "Sheet: " & sh.Name & " was not deleted!"
Else
HowManyDeleted = HowManyDeleted + 1
End If
On Error GoTo 0
Application.DisplayAlerts = True
End If
Next sh

MsgBox "Deleted: " & HowManyDeleted & " sheet(s)."

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Hello,

[quoted text clipped - 10 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...tions/201005/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...tions/201005/1

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
how do I delete a "Workbook" from the Excel menu? karenlee Excel Discussion (Misc queries) 3 July 30th 09 09:36 PM
how do I delete a "Workbook" from the Excel menu? karenlee Excel Discussion (Misc queries) 2 July 30th 09 07:43 PM
Excel ignores "Sheets in new workbook" setting [email protected] Excel Discussion (Misc queries) 3 February 21st 09 10:11 PM
Excel "Move or Copy" and "Delete" sheet functions dsiama Excel Worksheet Functions 1 December 28th 07 01:57 PM
How do I delete Sheets if "Delete" is greyed out? carriemca Excel Discussion (Misc queries) 1 April 10th 06 05:31 PM


All times are GMT +1. The time now is 05:08 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"