ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete all sheets but one (https://www.excelbanter.com/excel-programming/377937-delete-all-sheets-but-one.html)

hans[_3_]

delete all sheets but one
 
Is there a way to delete all sheets but the active one?

Thanks Hans



Bob Phillips

delete all sheets but one
 

Application.Displayalerts = False

For Each sh In Activeworkbook.Worksheets
If sh.Name < activesheet.name then
sh.Delete
End If
Next sh

Application.Displayalerts = True

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"hans" wrote in message
...
Is there a way to delete all sheets but the active one?

Thanks Hans





Sandy

delete all sheets but one
 
Sub DeleteAll()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
If Not ws Is ActiveSheet Then
ws.Delete
End If
Next
Application.DisplayAlerts = True
End Sub


Sandy

hans wrote:
Is there a way to delete all sheets but the active one?

Thanks Hans



hans[_3_]

delete all sheets but one
 
Thanks Hans


"Sandy" schreef in bericht
oups.com...
Sub DeleteAll()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
If Not ws Is ActiveSheet Then
ws.Delete
End If
Next
Application.DisplayAlerts = True
End Sub


Sandy

hans wrote:
Is there a way to delete all sheets but the active one?

Thanks Hans






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

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