Created
December 16, 2018 20:05
-
-
Save varunpalekar/36d830a940b4b470d9d6e79500d02747 to your computer and use it in GitHub Desktop.
Excel vba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Worksheet_SelectionChange(ByVal Target As Range) | |
If TypeName(Range("A" & Selection.Row).Value) = "Date" Then | |
Select Case Selection.Column | |
Case 2, 3, 4 | |
ActiveSheet.Unprotect Password:="123" | |
Target.Locked = True | |
ActiveSheet.Protect Password:="123" | |
If DateDiff("d", Range("A" & Selection.Row).Value, Now) = 0 Then | |
If DateDiff("n", Range("A" & Selection.Row).Value, Now) < 2 Then | |
ActiveSheet.Unprotect Password:="123" | |
Target.Locked = False | |
ActiveSheet.Protect Password:="123" | |
Else | |
MsgBox "Please contact HIBIRD admin" | |
End If | |
Else | |
MsgBox "Please contact HIBIRD admin" | |
End If | |
End Select | |
End If | |
If TypeName(Range("K" & Selection.Row).Value) = "Date" Then | |
Select Case Selection.Column | |
Case 12, 13 | |
ActiveSheet.Unprotect Password:="123" | |
Target.Locked = True | |
ActiveSheet.Protect Password:="123" | |
If DateDiff("d", Range("K" & Selection.Row).Value, Now) = 0 Then | |
If DateDiff("n", Range("K" & Selection.Row).Value, Now) < 2 Then | |
ActiveSheet.Unprotect Password:="123" | |
Target.Locked = False | |
ActiveSheet.Protect Password:="123" | |
Else | |
MsgBox "Please contact HIBIRD admin" | |
End If | |
Else | |
MsgBox "Please contact HIBIRD admin" | |
End If | |
End Select | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment