• Status: Solved
• Priority: Medium
• Security: Public
• Views: 325

# Protecting cells based on values in other cells

I have a protected worksheet that is used to order software licenses. There are three types of licenses with an input cell for each type(B13,B14,B15). The license types are mutually exclusive. Because of other formula based calculations I can not use a data validation drop down list.

What I want to accomplish: When a numeric value is entered into one of the three cells the other two are locked to prevent the possibility of ordering more than one type of license.

The cell have conditional formatting to gray out other two of the cells when a value is entered into one of the cells.
0
dnldsn
• 3
• 3
1 Solution

Older than dirtCommented:
``````Private Sub Worksheet_Change(ByVal Target As Range)
Case "\$B\$13"
If IsNumeric(Cells(13, 2).Value) Then
Range("B14", "B15").Locked = True
End If
Case "\$B\$14"
If IsNumeric(Cells(14, 2).Value) Then
Range("B13", "B15").Locked = True
End If
Case "\$B\$15"
If IsNumeric(Cells(15, 2).Value) Then
Range("B13", "B14").Locked = True
End If
End Select

End Sub
``````
0

Finance AnalystCommented:
You can apply Data Validation to the three cells such that only one cell gets completed by using a COUNT of the range B13:B15 and checking that it is less than or equal to 1.

Thanks
Rob H
0

Finance AnalystCommented:
Highlight cells B13:B15 and select Data Validation.

Choose Custom and enter following formula:

=COUNTA(\$B\$13:\$B\$15)<=1

Thanks
Rob H
0

Author Commented:
Rob

Nicely done. Thanks
0

Author Commented:
To: MartinLiss

When I try this solution I get the following error message:

"Run-time error '1004'
Unable to set the Locked property of the Range class"

Private Sub Worksheet_Change(ByVal Target As Range)
Case "\$B\$13"
If IsNumeric(Cells(13, 2).Value) Then
Range("B14", "B15").Locked = True
End If
Case "\$B\$14"
If IsNumeric(Cells(14, 2).Value) Then
Range("B13", "B15").Locked = True
End If
Case "\$B\$15"
If IsNumeric(Cells(15, 2).Value) Then
Range("B13", "B14").Locked = True
End If
End Select

End Sub
0

Finance AnalystCommented:
I was going to comment that I didn't think that would work cos need to unprotect the sheet first, in the macro possible, and reprotect after.

Rob
0

Author Commented:
Rob

Made the change to unprotect / protect worksheet and it now works.

Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.