Delete Worksheets With Specified Prefix - Excel Help & Excel Macro Help
SEARCH ENTIRE SITE LOADING..

Excel Help & Excel Best Practices Forums

 

Proudly Affiliated With: Intelligent Converters & AnalyserXL <Affiliate Program & ExcelUser Affiliate>

 

SPECIALS PAGE FOR BARGAINS | FREE EXCEL TRAINING | FREE CUSTOM FUNCTIONS ADD-IN


Go Back Excel Help & Excel Macro Help > HELP FORUMS > EXCEL HELP
HOME Register Forum Help Calendar Search For Today's Posts Mark Forums Read

Reply

Delete Worksheets With Specified Prefix

ANSWERS TO SIMILAR QUESTIONS
Prefix Cells With TextAdd Prefix To Selected CellsPrefix Text on EntryTrying to use IF Statement for Prefix only$ prefix for currency formula



Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com

Create Excel dashboards quickly with Plug-N-Play reports.


 
Thread Tools Search this Thread
Old 1 Week Ago
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
Samble Samble is offline
I agreed to these rules
 
I'm a Spammer: NO
MS Office Version: 2007 English
Op System: Windows Vista
Assumed Experience: Poor (know the very basics)
Join Date: 7th November 2009
English is 1st Language: Yes
Posts: 2 -- Threads: 0
Delete Worksheets With Specified Prefix

Hi

I am a beginner at this but I guess this is probably an easy one!

I have several excel workbooks with many worksheets (over 500 in some). Around a third of these worksheets are named "Exp1", "Exp2", "Exp3", etc.

I would like a macro that will delete all worksheets that do not have names starting with the letters "Exp". I do not want any confirmation dialogue, and as the workbooks vary in size, I would like it to finish when there are no sheets left (except the Exp ones of course).

Any ideas?

Thanks
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old 1 Week Ago
norie's Avatar
norie norie is offline
OzMVP
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 14th July 2004
English is 1st Language: Yes
Posts: 9,763 -- Threads: 21
Re: Delete Worksheets With Specified Prefix

Well for one workbook you could try this.
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub DelExpShts() Dim wb As Workbook Dim ws As Worksheet Application.DisplayAlerts = False Set wb = ThisWorkbook For Each ws In wb.Worksheets Select Case UCase(Left(ws. Name, 3)) Case "EXP" ws.Delete Case Else ' do nothing End Select Next ws Application.DisplayAlerts = True End Sub
__________________
Boo!
Print [Post / Thread] Reply With Quote
Old 1 Week Ago
Dave Hawley's Avatar
Dave Hawley Dave Hawley is offline
Administrator
 
I'm a Spammer: NO
MS Office Version: 2007 English
Op System: Windows Vista
Assumed Experience: Above Average
Join Date: 24th January 2003
English is 1st Language: Yes
Location: Australia
Posts: 49,233 -- Threads: 15169
Re: Delete Worksheets With Specified Prefix

This code will open all the Workbooks in a specified folder & path;
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Option Explicit Sub DeleteSheets() Dim wbOpen As Workbook Dim ws As Worksheet 'Change Path Const strPath As String = "C:\Excel\" Dim strExtension As String 'Comment out the 4 lines below to debug Application. ScreenUpdating = False Application.Calculation = xlCalculationManual Application.DisplayAlerts = False On Error Resume Next ChDir strPath 'Change extension strExtension = Dir("*.xls") Do While strExtension <> "" Set wbOpen = Workbooks.Open(strPath & strExtension) For Each ws In wbOpen.Worksheets If ws. Name Like "Exp*" Then ws.Delete Next ws strExtension = Dir Loop Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Application.DisplayAlerts = True On Error Goto 0 End Sub
Print [Post / Thread] Reply With Quote
Old 1 Week Ago
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
Samble Samble is offline
I agreed to these rules
 
I'm a Spammer: NO
MS Office Version: 2007 English
Op System: Windows Vista
Assumed Experience: Poor (know the very basics)
Join Date: 7th November 2009
English is 1st Language: Yes
Posts: 2 -- Threads: 0
Re: Delete Worksheets With Specified Prefix

Thanks for the help - this works a treat.

The option to do this to all files in a folder is a huge timesaver too!
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Reply Lifetime Upgrade To Ad Free Styles

   « PREVIOUS Determine Last Used Cell On Worksheet || Display Worsheet Range On UserForm NEXT »
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 20:00.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ozgrid is Not Associated With Microsoft. Ozgrid Retains the Rights to ALL Posts and Threads