PDA

View Full Version : disable cells based on time



flowergirl
08-10-2011, 10:44 PM
Hi,

I need to disable certain cells based on time. I.e. if current date is in March,certain cells would be disabled. Similarly for April and October....

I would appreciate your help.

p45cal
08-11-2011, 12:48 AM
First use Format Cells to unlock all/relevant cells on the sheet. Then protect the sheet (though the code below does this). This code will lock cells as the months go by:
Me.Protect userinterfaceonly:=True
Select Case Month(Date)
Case 4: Range("CertainCells").Locked = True 'April
Case 6: Range("JuneCells").Locked = True 'June
Case 8: Range("CertainOtherCells").Locked = True 'August
End Select
but this code will lock only a certain range according to the month, but will unlock the others:
Me.Protect userinterfaceonly:=True
Range("CertainCells").Locked = Month(Date) = 4 'April
Range("JuneCells").Locked = Month(Date) = 6 'June
Range("CertainOtherCells").Locked = Month(Date) = 8 'August
When this code is run is up to you - perhaps in a worksheet event, or a workbook_open event.

flowergirl
08-11-2011, 10:43 PM
Thanks a lot