Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Protect Worksheet Macro

Here's what I need some help with....
Have created a form in Excel that consists of cells in the first 7 rows are
a combination of locked and unlocked cells for the users entries. There are
also 9 rows at the bottom that are also locked and unlocked. Everything in
between these two areas needs to be unprotected so the user can make text
entries or combine cells to insert an object (graphic, chart or other). I
have created a toolbar with buttons that allow the user to unlock the
worksheet to have access to tools and processes they normally would not with
the sheet locked as well as another button that allows them to relock the
worksheet (yeah, like they are really gonna do that).

Is there a way to add code to the lock / unlock buttons that will relock the
two ranges at the top and bottom if the user clicks into either of these two
areas? Assistance as always, is greatly appreciated.

Regards - Lenny
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Protect Worksheet Macro

I left a MsgBox command in the code. You can safely remove that line of code
to make the process "quieter". I used it just to assure myself that things
were happeing properly.

"Lenny" wrote:

Here's what I need some help with....
Have created a form in Excel that consists of cells in the first 7 rows are
a combination of locked and unlocked cells for the users entries. There are
also 9 rows at the bottom that are also locked and unlocked. Everything in
between these two areas needs to be unprotected so the user can make text
entries or combine cells to insert an object (graphic, chart or other). I
have created a toolbar with buttons that allow the user to unlock the
worksheet to have access to tools and processes they normally would not with
the sheet locked as well as another button that allows them to relock the
worksheet (yeah, like they are really gonna do that).

Is there a way to add code to the lock / unlock buttons that will relock the
two ranges at the top and bottom if the user clicks into either of these two
areas? Assistance as always, is greatly appreciated.

Regards - Lenny

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Protect Worksheet Macro

The following is worksheet event code: open your workbook, select the sheet
you need this to work with. Right-click the sheet's name tab and choose
[View Code]. Copy the code below and paste it into the code module presented
to you. Edit the row numbers as required. Close the VB Editor and give it a
try.

Private Sub Worksheet_SelectionChange(ByVal _
Target As Range)
'lock the sheet if a cell in
'rows 1-7 or 20-28 is selected
If Target.Row < 8 Or (Target.Row 19 And _
Target.Row < 29) Then
ActiveSheet.Protect
MsgBox "Protecting sheet"
'or if you have a password
'ActiveSheet.Protect Password:="mypassword"
End If
End Sub

NOTE: you could modify this to seem really 'smart' by having the sheet
automatically unprotect itself when they click in one of the areas they are
allowed to work in and do away with your buttons!

Private Sub Worksheet_SelectionChange(ByVal _
Target As Range)
'lock the sheet if a cell in
'rows 1-7 or 20-28 is selected
If Target.Row < 8 Or (Target.Row 19 And _
Target.Row < 29) Then
'clicked in locked areas, protect the sheet
ActiveSheet.Protect
MsgBox "Protecting sheet"
'or if you have a password
'ActiveSheet.Protect Password:="mypassword"
Else
'clicked in area permitted to change
'unprotect the sheet
ActiveSheet.Unprotect
'or if you have a password
'ActiveSheet.Unprotect Password:="mypassword"
End If
End Sub




"Lenny" wrote:

Here's what I need some help with....
Have created a form in Excel that consists of cells in the first 7 rows are
a combination of locked and unlocked cells for the users entries. There are
also 9 rows at the bottom that are also locked and unlocked. Everything in
between these two areas needs to be unprotected so the user can make text
entries or combine cells to insert an object (graphic, chart or other). I
have created a toolbar with buttons that allow the user to unlock the
worksheet to have access to tools and processes they normally would not with
the sheet locked as well as another button that allows them to relock the
worksheet (yeah, like they are really gonna do that).

Is there a way to add code to the lock / unlock buttons that will relock the
two ranges at the top and bottom if the user clicks into either of these two
areas? Assistance as always, is greatly appreciated.

Regards - Lenny

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
Can protect worksheet then workbook but not Protect and Share in code [email protected] Excel Programming 7 January 16th 17 07:01 AM
Protect worksheet cells but still allow macro to edit chartproperties rrj Excel Programming 1 April 2nd 09 06:35 PM
Macro to Unprotect save worksheet and protect it again. holy41 Excel Programming 2 July 31st 06 09:47 PM
Add protect worksheet password in macro Kelly Excel Worksheet Functions 1 January 10th 06 02:08 AM
How to protect a worksheet from being copied to another worksheet SurvivorIT Excel Discussion (Misc queries) 3 August 31st 05 01:53 PM


All times are GMT +1. The time now is 09:49 PM.

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

About Us

"It's about Microsoft Excel"