Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Protecting a cell based on another cell


Hi,

For the active worksheet.... I need to do the following if possible....
If cells F10:F51 have "E" entered, then I need the corresponding cells in
G10:G51 to become protected or not allow anything to be entered into those
cells.
For Example:
If a user enterted "E" in F20, then G20 would not allow the user to entered
anything into it..

The sheet is already protected...and G10:G51 are not protected cells...

I'm not sure if this is possible...but if it is.. I 'm guessing it would
have to be done thru code.


Any help would be greatly appreciated..
Thanks in advance,
Kimberly


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Protecting a cell based on another cell

I suggest setting the EnableSelection property for the worksheet involved to
xlUnlockedCells so that the user can't even click on the locked cells in
column G. Otherwise, when they try to enter something, they will get an
annoying message saying "The cell you are trying to change is protected...".
I would suggest also toggling the cell interior colour from, say gray when
locked to white when unlocked, or similar. You might also want to consider,
instead of relying on the user to type in the "E", rigging it so that
clicking on the cells in column F toggles the "E", or alternatively, relying
on option buttons or some other method.

Instructions:
1) First unlock all cells on the worksheet that you want the user to be able
to select.
2) Then paste the following into the "ThisWorkbook" module. Note that it is
asummed that the worksheet is named "Data Entry".

Private Sub Workbook_Open()
With Sheets("Data Entry")
.Unprotect
.EnableSelection = xlUnlockedCells
.Protect UserInterfaceOnly:=True
End With
End Sub

3) Now paste the following into the worksheet's code module - e.g.
"Sheet1(Data Entry)":

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("F10:F51")
If Intersect(Target, rng) Is Nothing Then Exit Sub
Target(1, 2).Locked = (Trim(UCase(Target.Value)) = "E")
End Sub

4) Now close and reopen the workbook and try it out.

Regards,
Greg

"KimberlyC" wrote:


Hi,

For the active worksheet.... I need to do the following if possible....
If cells F10:F51 have "E" entered, then I need the corresponding cells in
G10:G51 to become protected or not allow anything to be entered into those
cells.
For Example:
If a user enterted "E" in F20, then G20 would not allow the user to entered
anything into it..

The sheet is already protected...and G10:G51 are not protected cells...

I'm not sure if this is possible...but if it is.. I 'm guessing it would
have to be done thru code.


Any help would be greatly appreciated..
Thanks in advance,
Kimberly



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Protecting a cell based on another cell

Further to my post, to avoid possible complications, you should replace the
line:
"If Intersect(Target, rng) Is Nothing Then Exit Sub"
With:
"If Intersect(Target, rng) Is Nothing Or _
Target.Count 1 Then Exit Sub"

Regards,
Greg

"Greg Wilson" wrote:

I suggest setting the EnableSelection property for the worksheet involved to
xlUnlockedCells so that the user can't even click on the locked cells in
column G. Otherwise, when they try to enter something, they will get an
annoying message saying "The cell you are trying to change is protected...".
I would suggest also toggling the cell interior colour from, say gray when
locked to white when unlocked, or similar. You might also want to consider,
instead of relying on the user to type in the "E", rigging it so that
clicking on the cells in column F toggles the "E", or alternatively, relying
on option buttons or some other method.

Instructions:
1) First unlock all cells on the worksheet that you want the user to be able
to select.
2) Then paste the following into the "ThisWorkbook" module. Note that it is
asummed that the worksheet is named "Data Entry".

Private Sub Workbook_Open()
With Sheets("Data Entry")
.Unprotect
.EnableSelection = xlUnlockedCells
.Protect UserInterfaceOnly:=True
End With
End Sub

3) Now paste the following into the worksheet's code module - e.g.
"Sheet1(Data Entry)":

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("F10:F51")
If Intersect(Target, rng) Is Nothing Then Exit Sub
Target(1, 2).Locked = (Trim(UCase(Target.Value)) = "E")
End Sub

4) Now close and reopen the workbook and try it out.

Regards,
Greg

"KimberlyC" wrote:


Hi,

For the active worksheet.... I need to do the following if possible....
If cells F10:F51 have "E" entered, then I need the corresponding cells in
G10:G51 to become protected or not allow anything to be entered into those
cells.
For Example:
If a user enterted "E" in F20, then G20 would not allow the user to entered
anything into it..

The sheet is already protected...and G10:G51 are not protected cells...

I'm not sure if this is possible...but if it is.. I 'm guessing it would
have to be done thru code.


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
Return cell address of a cell based on contents of cell. Danny Excel Worksheet Functions 4 November 15th 08 03:11 AM
Inputting cell value from source cell based on value in adjacent cell. michaelberrier Excel Discussion (Misc queries) 3 December 9th 06 09:16 PM
Cell Formula reference to cell Based On third Cell Content Gabriel Excel Discussion (Misc queries) 1 February 11th 05 06:36 AM
Cell Formula reference to cell Based On third Cell Content Gabriel Excel Discussion (Misc queries) 0 February 11th 05 05:35 AM
data validation to restrict input in cell based on value of cell above that cell NC Excel Programming 2 January 25th 05 07:11 AM


All times are GMT +1. The time now is 04:28 AM.

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"