LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 4,339
Default Lock Column

Hi,
I tried your code and it works OK. I opened/closed a workbook
several times, added new dates, saved and re-opened. All the columns were
protected. So what exacly doesn't work?

Note your code will protect empty cells - is this required?

XL2003

"Shobhit Bhatnagar" wrote:

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
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
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
Lock Column Tom Ogilvy Excel Programming 1 May 14th 05 03:53 PM
Lock Column Don Guillett[_4_] Excel Programming 0 May 13th 05 01:19 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 07:10 AM.

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"