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

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Delete sheets

Try the below macro and feedback. This works on the active workbook

Sub DeleteSheets()
strSheets = "Elevdata,Rapportvalidering,Kontrollark,Samlea rk"
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Delete sheets

Thank you Jacob. The program vorks perfekt
Thank you very much

  #4   Report Post  
Posted to microsoft.public.excel.programming
r r is offline
external usenet poster
 
Posts: 125
Default Delete sheets


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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Delete sheets


Thank you very much. It works



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Delete sheets

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
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
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:16 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:54 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 04:38 PM


All times are GMT +1. The time now is 03:51 PM.

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"