Greetings - i have the following bit of code to delete all but the visible sheet. it works fine, but I was wondering if there is a way to set the sheetcount back to 1 as part of this.
Right now, if I have sheets named like "sheet1", "sheet2" etc all the way up to "sheet30" and I run this procedure, it starts again at number 31 after sheets 1-30 are deleted. is there a way to reset this back to the lowest possible number? restarting excel does this, but I am wondering if it can be done through VBA.
What happens is that i have other procedures which add new sheets through VBA using worksheets.add. It is not that big of a deal, but I am curious!Code:Public Sub DeleteSheets()
Dim currentSheet As String
Dim varAnswer As String
Dim wsSheet As Worksheet
Dim strName As String
currentSheet = ActiveSheet.Name
varAnswer = MsgBox("This will delete all sheets except for the sheet named '" _
+ currentSheet + "'" + (Chr(13)) + (Chr(13)) + _
"Click Yes to irreversibly erase the other sheets, or No to cancel this procedure", _
vbYesNo, "Warning - This Procedure Can Not Be Undone!")
If varAnswer = vbNo Then
Exit Sub
Else:
Application.DisplayAlerts = False
With ActiveSheet
For Each wsSheet In Worksheets
strName = wsSheet.Name
If strName <> currentSheet Then
wsSheet.Delete
End If
Next wsSheet
End With
end if
Application.DisplayAlerts = True
End Sub