PC Review


Reply
Thread Tools Rate Thread

Delete sheets

 
 
Sverre
Guest
Posts: n/a
 
      9th Jun 2009
I have a workbook with many diefferent sheets. I need a makro to delete all
sheets except 4 sheets named:
Elevdata,
Rapportvalidering,
Kontrollark,
Samleark,

It is not possible to record a makro because the sheets can appear with
different names.

Regards Sverre


 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      9th Jun 2009
Try the below macro and feedback. This works on the active workbook

Sub DeleteSheets()
strSheets = "Elevdata,Rapportvalidering,Kontrollark,Samleark"
Application.DisplayAlerts = False
For intTemp = Sheets.Count To 1 Step -1
If InStr(1, "," & strSheets & ",", "," & _
Sheets(intTemp).Name & ",", vbTextCompare) = 0 Then
Sheets(intTemp).Delete
End If
Next
Application.DisplayAlerts = True
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:

> I have a workbook with many diefferent sheets. I need a makro to delete all
> sheets except 4 sheets named:
> Elevdata,
> Rapportvalidering,
> Kontrollark,
> Samleark,
>
> It is not possible to record a makro because the sheets can appear with
> different names.
>
> Regards Sverre
>
>

 
Reply With Quote
 
r
Guest
Posts: n/a
 
      9th Jun 2009

Sub Delete_SH()
Dim v As Worksheet, l As Long
Const s As String = "Elevdata Rapportvalidering Kontrollark Samleark"
l = Len(s)
Application.DisplayAlerts = False
For Each v In Worksheets
If l = Len(VBA.Replace(s, v.Name, "")) Then _
v.Delete
Next
Application.DisplayAlerts = True
End Sub

regards
r

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/...ternative.html


"Sverre" wrote:

> I have a workbook with many diefferent sheets. I need a makro to delete all
> sheets except 4 sheets named:
> Elevdata,
> Rapportvalidering,
> Kontrollark,
> Samleark,
>
> It is not possible to record a makro because the sheets can appear with
> different names.
>
> Regards Sverre
>
>

 
Reply With Quote
 
Sverre
Guest
Posts: n/a
 
      9th Jun 2009
Thank you Jacob. The program vorks perfekt
Thank you very much

 
Reply With Quote
 
Sverre
Guest
Posts: n/a
 
      9th Jun 2009

Thank you very much. It works

 
Reply With Quote
 
keiji kounoike
Guest
Posts: n/a
 
      9th Jun 2009
I think it is rather difficult to input sheet's name correctly. if the
number of the sheets you want to leave is a few compared to the sheets
you want to delete, first select all the sheets you want to leave, then
run the macro below.

Sub Delunselectedsheets()
Dim v As Sheets, sh As Worksheet
Dim arr()
Dim i As Long

Set v = ActiveWindow.SelectedSheets
ReDim arr(v.Count - 1)
For Each sh In v
arr(i) = sh.Name
i = i + 1
Next

Application.DisplayAlerts = False
For Each sh In Worksheets
If IsError(Application.Match(sh.Name, arr, 0)) Then
sh.Delete
End If
Next
End Sub

Keiji

Sverre wrote:
> I have a workbook with many diefferent sheets. I need a makro to delete all
> sheets except 4 sheets named:
> Elevdata,
> Rapportvalidering,
> Kontrollark,
> Samleark,
>
> It is not possible to record a makro because the sheets can appear with
> different names.
>
> Regards Sverre
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sub to delete all sheets other than x, y, z Max Microsoft Excel Programming 6 2nd Jan 2008 01:04 AM
Delete Sheets Andibevan Microsoft Excel Programming 3 24th Jun 2005 12:17 AM
Re: Macro to delete sheets and saves remaining file does not properly delete module gazornenplat Microsoft Excel Programming 0 22nd Jun 2005 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Microsoft Excel Programming 7 21st Jun 2005 05:16 PM
delete all sheets except... caroline Microsoft Excel Programming 4 22nd May 2004 04:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:16 PM.