View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Amanda Amanda is offline
external usenet poster
 
Posts: 151
Default lock cell based on a condition

Thanks...I'm trying to figure this out...

Question, I was actually simplifying the b & c column....the "x" is in
Column B, and the column I need locked is H.....what needs to change for that
to happen?

Thanks again for your help

"Gary''s Student" wrote:

We will enter and run two pieces of code:

1. put this in a standard module:

Sub set_up()
ActiveSheet.Unprotect
Cells.Locked = False
Cells.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True,
AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub

It leaves all cells unlocked and the sheet protected. Run this once before
editing


2. put this event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("B:B"), Target) Is Nothing Then
Exit Sub
End If

ActiveSheet.Unprotect
If Target.Value = "x" Then
Target.Offset(0, 1).Locked = True
Else
Target.Offset(0, 1).Locked = False
End If
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True

ActiveSheet.EnableSelection = xlUnlockedCells
End Sub

This code checks every entry made in column B. If it is x, then the
adjacent cell in column C is locked. If it is not x, then the adjacent cell
in column C is unlocked.

If you have never used VBA before, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm
--
Gary''s Student - gsnu200731


"Amanda" wrote:

I would like a cell to be locked or unfillable based on the results of
another cell.

For example:
Column B has a formula that the results are "" or "x".
If possible, I would like to lock Colum C for those that return an "x" value.

Is this possible?
Thanks

PS I saw a bunch of messages about code, but I have no idea what that is....