#1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming,microsoft.public.excel.misc
external usenet poster
 
Posts: 27,285
Default Lock Column

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





  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming,microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Lock Column

Tom,
Thanks a lot for clarifying it, i tested it now it works for every date and
column.

Regards,
Shobhit Bhatnagar



"Tom Ogilvy" wrote in message
...
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







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
Need to lock one column and allow others to scroll Milazzolane Excel Discussion (Misc queries) 1 October 13th 08 05:45 PM
Lock column/row in place pelachrum Excel Discussion (Misc queries) 1 July 24th 06 07:30 AM
How to lock a column Patty via OfficeKB.com Excel Discussion (Misc queries) 1 September 23rd 05 06:57 PM
Lock Column Shobhit Bhatnagar Excel Discussion (Misc queries) 6 May 14th 05 03:53 PM
Protect or Lock Column Tom LeBold Excel Programming 3 March 25th 05 08:53 AM


All times are GMT +1. The time now is 10:47 PM.

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"