Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Protecting cells based on values in other cells

Posted on 2014-03-21
Medium Priority
297 Views
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
Question by:dnldsn
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 3
• 3

LVL 49

Expert Comment

ID: 39945434
``````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

LVL 33

Expert Comment

ID: 39945504
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

LVL 33

Accepted Solution

Rob Henson earned 2000 total points
ID: 39945529
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 Closing Comment

ID: 39946013
Rob

Nicely done. Thanks
0

Author Comment

ID: 39946025
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

LVL 33

Expert Comment

ID: 39946710
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 Comment

ID: 39946762
Rob

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

Thanks again.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to usâ€¦
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaacâ€¦
###### Suggested Courses
Course of the Month10 days, 17 hours left to enroll

#### 618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.