abhirupganguli123
Board Regular
- Joined
- Feb 25, 2014
- Messages
- 55
Hello,
I have a spreadsheet with row wise dates in column A.
I need a vba code to automatically protect cells with password from column A to J (row wise) when Today's date is passed. Could anyone help me with a code? The code should not start with Sub "Private Sub Worksheet_Change" as I already have a code written in the worksheet module with same sub, so as I know two Change mode codes will not work in a same module.
I have got a code, but it is not working as whenever I double click on a cell it gets opened. On the fist double click it says protected, but on the second double click it gets opened. Could you please rectify this code or provide a new one ?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A" & Selection.Row).Value < Date Then
ActiveSheet.Protect Password:="accountancy"
MsgBox "Only today's time can be edited!"
ElseIf Range("A" & Selection.Row).Value >= Date Then
ActiveSheet.Unprotect Password:="accountancy"
ActiveSheet.EnableSelection = xlNoRestrictions
End If
End Sub
I have a spreadsheet with row wise dates in column A.
I need a vba code to automatically protect cells with password from column A to J (row wise) when Today's date is passed. Could anyone help me with a code? The code should not start with Sub "Private Sub Worksheet_Change" as I already have a code written in the worksheet module with same sub, so as I know two Change mode codes will not work in a same module.
I have got a code, but it is not working as whenever I double click on a cell it gets opened. On the fist double click it says protected, but on the second double click it gets opened. Could you please rectify this code or provide a new one ?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A" & Selection.Row).Value < Date Then
ActiveSheet.Protect Password:="accountancy"
MsgBox "Only today's time can be edited!"
ElseIf Range("A" & Selection.Row).Value >= Date Then
ActiveSheet.Unprotect Password:="accountancy"
ActiveSheet.EnableSelection = xlNoRestrictions
End If
End Sub