Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Code to check for active worksheet

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Code to check for active worksheet

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.

"KimberlyC" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code to check for active worksheet

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

--
Regards,
Tom Ogilvy


KimberlyC wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you view an active macro code? Scott Excel Discussion (Misc queries) 4 February 9th 10 07:53 PM
Need VBA Code to Let User Define Active Sheet zulfer7 Excel Discussion (Misc queries) 3 March 29th 07 02:59 PM
What is the code for the active worksheet? Dr Dan[_2_] Excel Discussion (Misc queries) 12 February 23rd 07 03:12 PM
How to Add Rows From Active Cell with in a XLL Code Sheraz Excel Worksheet Functions 0 August 8th 06 01:17 PM
Code to print most (not all) pages within active workbook AlanN Excel Programming 7 August 8th 03 05:26 PM


All times are GMT +1. The time now is 09:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"