Code to check for active worksheet

  • Thread starter Thread starter KimberlyC
  • Start date Start date
K

KimberlyC

Hi
I have code that deletes the active worksheet that the user is viewing. I
have four worksheets within the workbook that I do not want the user to be
able to delete.
I would like to have the code check and make sure the user in not currently
on any of those 4 worksheets and if they are not...then have the code run to
delete the active worksheet.. if they are on any one of those 4
sheets...then a message would pop up stating " cannot delete active
worksheet......"

I'm sure how to do this properly.
Any help would be greatly appreciated.

Thanks in advance.
Kimberly
 
Hi Kimberly:

With ActiveSheet
If .Name <> "Name1" And .Name <>"Name2" And _
.Name <> "Name3" And .Name <> "Name4" Then
.Delete
Else
MsgBox "Cannot delete active worksheet."
End If
End With

Regards,

Vasant.
 
Sub Deletesheet()
Dim sName as String
sName = lcase(activesheet.name)
Select Case sName
Case "sheet1"
msgbox "Sheet1 cannot be deleted"
Case "sheet2"
msgbox "Sheet2 cannot be deleted"
Case "sheet3
msgbox "Sheet3 cannot be deleted"
Case "sheet4"
msgbox "Sheet4 cannot be deleted"
Case Else
Application.DisplayAlerts = False
worksheets(sName).Delete
Application.DisplayAlerts = True
End Select
End Sub
 
Back
Top