Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi, i need a macro to delete all sheets except 4 or 5 sheets.
Can this be done? Thanks! |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro To Delete/Add & Rename/Arrange Sheets | Excel Discussion (Misc queries) | |||
Macro to delete unwanted sheets | Excel Discussion (Misc queries) | |||
How do I delete Sheets if "Delete" is greyed out? | Excel Discussion (Misc queries) | |||
How can I delete a macro when the Delete button is not active? | Excel Worksheet Functions | |||
How do i delete a macro in Excel 2003 when delete isn't highlight | Excel Discussion (Misc queries) |