PDA

View Full Version : deletea ll sheets



lior03
06-14-2006, 04:05 AM
hello
i am trying to delete all sheets in a workbook,except the active sheet.
whats wrong with this code

On Error Resume Next
Dim wkSt As String
Dim wkBk As Worksheet
wkSt = ActiveSheet.Name
For Each wkBk In ActiveWorkbook.Worksheets
wkBk.Activate
If wkBk.Name <> wkSt Then
wkBk.Delete
End If
Next


thanks

mdmackillop
06-14-2006, 04:26 AM
Hi Moshe,
No need to activate the sheets, and avoid the warning messages.

On Error Resume Next
Dim wkSt As String
Dim wkBk As Worksheet
wkSt = ActiveSheet.Name
Application.DisplayAlerts = False
For Each wkBk In ActiveWorkbook.Worksheets
If wkBk.Name <> wkSt Then wkBk.Delete
Next
Application.DisplayAlerts = True