PDA

View Full Version : Solved: Locking cells dependent on other cells



Red Smurf
09-03-2008, 04:51 AM
Hi,

I'm trying to lock cells in a range on a particular sheet depending on the contents of another range of cells. ie If column C contains dates, both historic and future, then if the date in column C is prior to todays date then the corresponding cell is column G needs to be locked regardless of whether it has anything in it or not. Can anyone help?

Below is what I've put together so far, locking the entire row rather than just the required cell, but unfortuanately it doesn't work:


Sub locking()
Dim c As Range
'Today's date is entered is cell D6
Set d = cell("D6").Value

For Each c In Range("C9", "C400").Select
If c < d Then
c.EntireRow.Locked = False
Else
c.EntireRow.Locked = True
End If
Next cell
End Sub

Could you tell me where I've gone wrong?

Many thanks,

Bob Phillips
09-03-2008, 05:32 AM
Sub locking()
Dim c As Range
Dim d As Long
'Today's date is entered is cell D6
d = Range("D6").Value

For Each c In Range("C9", "C400")
c.EntireRow.Locked = c >= d
Next c
End Sub