Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel,microsoft.public.excel.programming,microsoft.public.excel.misc
|
|||
|
|||
![]()
comparing dates that way would be inaccurate. to illustarte from the
immediate window: ? "01/12/2005" < "03/01/1995" True Private Sub Workbook_Open() Dim cell As Range Worksheets("May_05").Activate ActiveSheet.Unprotect Password:="mypass" For Each cell In Rows(1).Cells If cell.Value2 < clng(Date) - 1 Then cell.EntireColumn.Locked = True Else cell.EntireColumn.Locked = False End If Next ActiveSheet.Protect Password:="mypass" End Sub -- Regards, Tom Ogilvy "Shobhit Bhatnagar" wrote in message ... I have created a worksheet(May_05), in which i am trying to lock the columns based on date values, if the first row of the colums has a date lower than the current date the whole column should get locked, It works but only sometimes. Following is the code i am using. Private Sub Workbook_Open() Dim cell As Range Worksheets("May_05").Activate ActiveSheet.Unprotect Password:="mypass" For Each cell In Rows(1).Cells If cell.Text < Format(Date - 1, "dd/mm/yyyy") Then cell.EntireColumn.Locked = True Else cell.EntireColumn.Locked = False End If Next ActiveSheet.Protect Password:="mypass" End Sub Please let me know if i am doing anything wrong or is there a better way to achieve the same. I am also attaching my workbook for the same. Thanks for your help in advance. Shobhit Bhatnagar |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Need to lock one column and allow others to scroll | Excel Discussion (Misc queries) | |||
Lock column/row in place | Excel Discussion (Misc queries) | |||
How to lock a column | Excel Discussion (Misc queries) | |||
Lock Column | Excel Discussion (Misc queries) | |||
Protect or Lock Column | Excel Programming |