vba code will not lock certain ranges after workbook save

lucad

New Member
Joined
Jan 26, 2014
Messages
2
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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Thought that i might add that the cells that i want to block are validated with a defined list of numbers... If i take this off and just have the cells plain cells with out a drop down list then it works... maybe the code needs to have the .value to be changed to something that suits the list ie .select ?
 
Upvote 0

Forum statistics

Threads
1,215,130
Messages
6,123,220
Members
449,091
Latest member
jeremy_bp001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top