Hi Rajesh,
Replace the existing code with the following. Save and close the workbook. Open the workbook again. (The code will run on opening the workbook)
Code:Private Sub Workbook_Open() Dim wksTarget As Worksheet Dim rngDate As Range Dim rngData As Range Dim c As Long Dim LastRow As Long Dim LastCol As Long Const Pwd As String = "pwd" '<< adjust to suit Set wksTarget = ThisWorkbook.Worksheets("Sheet1") '<< adjust to suit If Not blnUnlockedAllCells Then wksTarget.Protect Password:=Pwd, userinterfaceonly:=True wksTarget.Cells.Locked = False blnUnlockedAllCells = True End If Set rngData = wksTarget.Range("c2:p12") '<< adjust to suit. range including the date row For c = 1 To rngData.Columns.Count If CDate(rngData(1, c)) <= Date - 2 Then On Error Resume Next rngData.Columns(c).SpecialCells(2).Locked = True On Error GoTo 0 End If Next End Sub




Reply With Quote
Bookmarks