ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA Code Required for deleting All Sheets except Sheet1 (https://www.excelbanter.com/excel-discussion-misc-queries/247308-vba-code-required-deleting-all-sheets-except-sheet1.html)

Ms-Exl-Learner

VBA Code Required for deleting All Sheets except Sheet1
 
Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------


Jarek Kujawa[_2_]

VBA Code Required for deleting All Sheets except Sheet1
 
Sub delsheets()
Dim sh as Sheet

For Each sh in ActiveWorkbook.Sheets
If sh.Name<"Sheet1" Then
sh.Delete
End If
Next sh

End Sub

On 3 Lis, 09:46, Ms-Exl-Learner wrote:
Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------



Gary''s Student

VBA Code Required for deleting All Sheets except Sheet1
 
Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub

--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------


Ms-Exl-Learner

VBA Code Required for deleting All Sheets except Sheet1
 
Thank you its working fine but if I run the Macro then its asking me to
Confirm Do you want to delete this sheet like that for each and every
worksheet before deleting. I am having 200 sheets for 200 times I need to
click or Press enter for deleting the sheets.

Please help me€¦

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub

--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------


Ms-Exl-Learner

VBA Code Required for deleting All Sheets except Sheet1
 
Not for 200 times 199 times. Please set the macro without any message box
confirmation.

--------------------
(Ms-Exl-Learner)
--------------------



"Ms-Exl-Learner" wrote:

Thank you its working fine but if I run the Macro then its asking me to
Confirm Do you want to delete this sheet like that for each and every
worksheet before deleting. I am having 200 sheets for 200 times I need to
click or Press enter for deleting the sheets.

Please help me€¦

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub

--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------


Gary''s Student

VBA Code Required for deleting All Sheets except Sheet1
 
Sub SheetRemover()
k = Sheets.Count
Application.DisplayAlerts = False
For i = k To 2 Step -1
Sheets(i).Delete
Next
Application.DisplayAlerts = True
End Sub


--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Not for 200 times 199 times. Please set the macro without any message box
confirmation.

--------------------
(Ms-Exl-Learner)
--------------------



"Ms-Exl-Learner" wrote:

Thank you its working fine but if I run the Macro then its asking me to
Confirm Do you want to delete this sheet like that for each and every
worksheet before deleting. I am having 200 sheets for 200 times I need to
click or Press enter for deleting the sheets.

Please help me€¦

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub

--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------


Ms-Exl-Learner

VBA Code Required for deleting All Sheets except Sheet1
 
Thank you very much its working fine now€¦

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

Sub SheetRemover()
k = Sheets.Count
Application.DisplayAlerts = False
For i = k To 2 Step -1
Sheets(i).Delete
Next
Application.DisplayAlerts = True
End Sub


--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Not for 200 times 199 times. Please set the macro without any message box
confirmation.

--------------------
(Ms-Exl-Learner)
--------------------



"Ms-Exl-Learner" wrote:

Thank you its working fine but if I run the Macro then its asking me to
Confirm Do you want to delete this sheet like that for each and every
worksheet before deleting. I am having 200 sheets for 200 times I need to
click or Press enter for deleting the sheets.

Please help me€¦

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub

--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------


Jarek Kujawa[_2_]

VBA Code Required for deleting All Sheets except Sheet1
 
forgot to include the

Application.DisplayAlerts = False
....
Application.DisplayAlerts = True

part


On 3 Lis, 10:10, Jarek Kujawa wrote:
Sub delsheets()
Dim sh as Sheet

For Each sh in ActiveWorkbook.Sheets
If sh.Name<"Sheet1" Then
sh.Delete
End If
Next sh

End Sub

On 3 Lis, 09:46, Ms-Exl-Learner wrote:



Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.


Thanks for reading.


--------------------
(Ms-Exl-Learner)
--------------------- Ukryj cytowany tekst -


- Pokaż cytowany tekst -




All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com