I have a range of cells with data that i want to lock after/on save if certain criteria is met.
code:
Sub Workbook_AfterSave(ByVal Success As Boolean)
If Sheets("JANUARY").Range("BE10").Value = "--" And Range("BF10").Value = "--" And Range("BG10").Value = "--" And Range("BH10").Value = "--" Then
Sheets("JANUARY").Unprotect
Sheets("JANUARY").Range("BD10").Locked = False
Sheets("JANUARY").Range("BE10:BH10").Locked = False
Sheets("JANUARY").Protect
Else
Sheets("JANUARY").Unprotect
Sheets("JANUARY").Range("BD10").Locked = True
Sheets("JANUARY").Range("BE10:BH10").Locked = True
Sheets("JANUARY").Protect
End If
the logic in this is straight forward but i just cant understand why i get an error if i want to lock the range BD10? if i remove those lines the other ranges, BE10:BH10 lock fine.
can somone please help me and explain why this is the case... thanks in advance
code:
Sub Workbook_AfterSave(ByVal Success As Boolean)
If Sheets("JANUARY").Range("BE10").Value = "--" And Range("BF10").Value = "--" And Range("BG10").Value = "--" And Range("BH10").Value = "--" Then
Sheets("JANUARY").Unprotect
Sheets("JANUARY").Range("BD10").Locked = False
Sheets("JANUARY").Range("BE10:BH10").Locked = False
Sheets("JANUARY").Protect
Else
Sheets("JANUARY").Unprotect
Sheets("JANUARY").Range("BD10").Locked = True
Sheets("JANUARY").Range("BE10:BH10").Locked = True
Sheets("JANUARY").Protect
End If
the logic in this is straight forward but i just cant understand why i get an error if i want to lock the range BD10? if i remove those lines the other ranges, BE10:BH10 lock fine.
can somone please help me and explain why this is the case... thanks in advance