Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Looking for a sub which would delete all sheets
other than 3 sheets named as: x, y, z. Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
here's one way, give this a try:
Option Explicit Sub remove_some_sheets() Dim ws As Worksheet Application.DisplayAlerts = False For Each ws In ThisWorkbook.Worksheets If ws.Name < "x" And ws.Name < "y" And ws.Name < "z" Then ws.Delete End If Next Application.DisplayAlerts = True End Sub -- Gary "Max" wrote in message ... Looking for a sub which would delete all sheets other than 3 sheets named as: x, y, z. Thanks. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Works well, Gary. Thanks.
|
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub delShts()
Dim sh As Worksheet For Each sh In ActiveWorkbook.Worksheets If sh.Name < "x" And sh.Name < "y" And sh.Name < "z" Then sh.Delete End If Next End Sub "Max" wrote: Looking for a sub which would delete all sheets other than 3 sheets named as: x, y, z. Thanks. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, JLGWhiz
It works well too, after I inserted the lines: Application.DisplayAlerts = False .... Application.DisplayAlerts = True (took the cue from Gary's sub) |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try something like the following. In this code, the sheet names must be in
UPPER CASE unless you have an "Option Compare Text" statement at the top of the module (before and outside of any procedures), in which case the case of the name doesn't matter. Dim WS As Worksheet For Each WS In ThisWorkbook.Worksheets Select Case UCase(WS.Name) Case "X", "Y", "Z" ' do nothing Case Else Application.DisplayAlerts = False WS.Delete Application.DisplayAlerts = True End Select Next WS -- Cordially, Chip Pearson Microsoft MVP - Excel, 10 Years Pearson Software Consulting www.cpearson.com (email on the web site) "Max" wrote in message ... Looking for a sub which would delete all sheets other than 3 sheets named as: x, y, z. Thanks. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, Chip ! That works well, too.
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming |