Locking/Unlocking Cells Based on Value

gatorbait

New Member
Joined
Nov 25, 2008
Messages
36
I'm trying to lock or unlock cells based on the value of another cell, but I keep running into an error and need some assistance.

I've created a spreadsheet with a data validation list in column J. When the value in column J is "Default", the adjacent cells K-M are locked. If the user needs to change the default values in K-M, the user can unlock these cells by changing the drop down list in column J to "Override Values".

I'm using a custom data validation for columns K-M, =$J$17:$J$64<>"Default". The cells are being locked/unlocked using the following VBA code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("J17") = "Override Credit %" Then
Range("K17:M64").Locked = False
ElseIf Range("J17") = "Default" Then
Range("K17:M64").Locked = True
End If
End Sub

Everything works when there is no other data in the spreadsheet, but as soon as I enter data and try to change a value in columns K-M I get the following error:

"This value doesn't match the data validation restrictions defined for this cell".

I can't seem to figure out the why. Can anyone tell me what I'm doing wrong?

Thanks in advance for your assistance.
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

gatorbait

New Member
Joined
Nov 25, 2008
Messages
36
I should note the data validation list is Default or Override Credit % (same as the VBA code) and not "Override Values" as I stated above.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,514
Messages
5,602,093
Members
414,501
Latest member
mdhaumyu

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
Top