Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-delete all sheets except

Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default macro-delete all sheets except

Mention the sheets not to be deleted in the string variable comma separated
without any spaces.. and try the macro
strSheet = "Sheet1,Sheet2"

Sub Macro()
Dim strSheet As String
strSheet = "Sheet1,Sheet2"
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
End Sub

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


"puiuluipui" wrote:

Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done?
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-delete all sheets except

Hi Jacob, it's working, but it ask me everytime if i really want to delete.
Can this code be modify to display a message "did you saved previous month?"
and then, if i click ok, to delete all sheets without asking anithing else?
If i click cancel, to stop the macro , so i can save previous month.
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Mention the sheets not to be deleted in the string variable comma separated
without any spaces.. and try the macro
strSheet = "Sheet1,Sheet2"

Sub Macro()
Dim strSheet As String
strSheet = "Sheet1,Sheet2"
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
End Sub

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


"puiuluipui" wrote:

Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done?
Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-delete all sheets except

Hi Don, it's ok, but i need a simple msgbox with ok and cancel. Now i have a
msgbox with input message
Can this be done?
Thanks!

"Don Guillett" wrote:

Sub Macro()

Dim strSheet As String
x = InputBox("did", vbOKCancel)
If x = OK Then 'MsgBox "hi"

strSheet = "Sheet1,Sheet2"
application.displayalerts=false
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
application.displayalerts=true
end if
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"puiuluipui" wrote in message
...
Hi Jacob, it's working, but it ask me everytime if i really want to
delete.
Can this code be modify to display a message "did you saved previous
month?"
and then, if i click ok, to delete all sheets without asking anithing
else?
If i click cancel, to stop the macro , so i can save previous month.
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Mention the sheets not to be deleted in the string variable comma
separated
without any spaces.. and try the macro
strSheet = "Sheet1,Sheet2"

Sub Macro()
Dim strSheet As String
strSheet = "Sheet1,Sheet2"
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
End Sub

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


"puiuluipui" wrote:

Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done?
Thanks!





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default macro-delete all sheets except

Modifying Don's coding...

Sub Macro()

Dim strSheet As String
x = MsgBox("Did you save previous month?", vbOKCancel)
If x = vbCancel Then Exit Sub

strSheet = "Sheet1,Sheet2"
application.displayalerts=false
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
application.displayalerts=true
end if
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"puiuluipui" wrote:

Hi Don, it's ok, but i need a simple msgbox with ok and cancel. Now i have a
msgbox with input message
Can this be done?
Thanks!

"Don Guillett" wrote:

Sub Macro()

Dim strSheet As String
x = InputBox("did", vbOKCancel)
If x = OK Then 'MsgBox "hi"

strSheet = "Sheet1,Sheet2"
application.displayalerts=false
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
application.displayalerts=true
end if
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"puiuluipui" wrote in message
...
Hi Jacob, it's working, but it ask me everytime if i really want to
delete.
Can this code be modify to display a message "did you saved previous
month?"
and then, if i click ok, to delete all sheets without asking anithing
else?
If i click cancel, to stop the macro , so i can save previous month.
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Mention the sheets not to be deleted in the string variable comma
separated
without any spaces.. and try the macro
strSheet = "Sheet1,Sheet2"

Sub Macro()
Dim strSheet As String
strSheet = "Sheet1,Sheet2"
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
End Sub

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


"puiuluipui" wrote:

Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done?
Thanks!



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-delete all sheets except

Thanks you all!

"Luke M" wrote:

Modifying Don's coding...

Sub Macro()

Dim strSheet As String
x = MsgBox("Did you save previous month?", vbOKCancel)
If x = vbCancel Then Exit Sub

strSheet = "Sheet1,Sheet2"
application.displayalerts=false
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
application.displayalerts=true
end if
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"puiuluipui" wrote:

Hi Don, it's ok, but i need a simple msgbox with ok and cancel. Now i have a
msgbox with input message
Can this be done?
Thanks!

"Don Guillett" wrote:

Sub Macro()

Dim strSheet As String
x = InputBox("did", vbOKCancel)
If x = OK Then 'MsgBox "hi"

strSheet = "Sheet1,Sheet2"
application.displayalerts=false
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
application.displayalerts=true
end if
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"puiuluipui" wrote in message
...
Hi Jacob, it's working, but it ask me everytime if i really want to
delete.
Can this code be modify to display a message "did you saved previous
month?"
and then, if i click ok, to delete all sheets without asking anithing
else?
If i click cancel, to stop the macro , so i can save previous month.
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Mention the sheets not to be deleted in the string variable comma
separated
without any spaces.. and try the macro
strSheet = "Sheet1,Sheet2"

Sub Macro()
Dim strSheet As String
strSheet = "Sheet1,Sheet2"
For Each sh In Worksheets
If InStr(1, "," & strSheet & ",", "," & sh.Name & ",", _
vbTextCompare) = 0 Then sh.Delete
Next
End Sub

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


"puiuluipui" wrote:

Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done?
Thanks!


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/Add & Rename/Arrange Sheets steven.holloway Excel Discussion (Misc queries) 5 June 13th 08 06:40 PM
Macro to delete unwanted sheets Sal Excel Discussion (Misc queries) 5 March 15th 07 09:33 PM
How do I delete Sheets if "Delete" is greyed out? carriemca Excel Discussion (Misc queries) 1 April 10th 06 05:31 PM
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM


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

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"