Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Deleting Sheets

Lets say i have a workbook with 20 sheets on it though the
number may vary and I want to delete all sheets which
arent named "Control", "Menu" and "Table"

How could i accomplish this with VBA?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Deleting Sheets

Jordan,

Try something like the following:

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Select Case WS.Name
Case "Control", "Menu", "Table"
Case Else
WS.Delete
End Select
Next WS

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Jordan" wrote in message
...
Lets say i have a workbook with 20 sheets on it though the
number may vary and I want to delete all sheets which
arent named "Control", "Menu" and "Table"

How could i accomplish this with VBA?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Deleting Sheets

Hi Jordan
similar to a post 2 hours ago try
----
Public Sub delete_sheets()
Dim wkSht As Worksheet
Application.DisplayAlerts = False
For Each wkSht In Worksheets
If Lcase(trim(wkSht.Name)) < "Control" and
Lcase(trim(wkSht.Name)) _
< "Menu" Lcase(trim(wkSht.Name)) < "Table" Then
wkSht.Delete
End If
Next wkSht
Application.DisplayAlerts = True
End Sub

Frank

Jordan wrote:
Lets say i have a workbook with 20 sheets on it though the
number may vary and I want to delete all sheets which
arent named "Control", "Menu" and "Table"

How could i accomplish this with VBA?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Deleting Sheets

Jordan,

A better version is below:

Dim WS As Worksheet
Application.DisplayAlerts = False
For Each WS In ThisWorkbook.Worksheets
Select Case WS.Name
Case "Control", "Menu", "Table"
Case Else
WS.Delete
End Select
If ThisWorkbook.Worksheets.Count = 1 Then
Exit For
End If
Next WS
Application.DisplayAlerts = True

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jordan" wrote in message
...
Lets say i have a workbook with 20 sheets on it though the
number may vary and I want to delete all sheets which
arent named "Control", "Menu" and "Table"

How could i accomplish this with VBA?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Deleting Sheets

Hi Jordan,

How was the jungle?

Application.DisplayAlerts = False
For Each sh In Activeworkbook.Worksheets
If sh.Name < "Control" And sh.Name < "Menu" And _
sh.Name < "Table" Then
sh.Delete
End If
Next sh
Application.DisplayAlerts = True

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jordan" wrote in message
...
Lets say i have a workbook with 20 sheets on it though the
number may vary and I want to delete all sheets which
arent named "Control", "Menu" and "Table"

How could i accomplish this with VBA?



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 sheets 2&3 doug53098 Excel Discussion (Misc queries) 2 July 7th 05 08:22 PM
deleting sheets KLP Excel Discussion (Misc queries) 3 January 14th 05 12:24 AM
Deleting All Sheets Other than specified from a workbook Nic@Rolls-Royce[_9_] Excel Programming 10 February 13th 04 03:10 PM
Deleting sheets Gary Adamson[_2_] Excel Programming 2 October 30th 03 07:24 PM
deleting sheets david Excel Programming 2 July 31st 03 01:02 AM


All times are GMT +1. The time now is 08:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"