Solved

Protecting cells based on values in other cells

Posted on 2014-03-21
7
270 Views
Last Modified: 2014-03-21
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
Comment
Question by:dnldsn
  • 3
  • 3
7 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 39945434
Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target.Address
        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

Open in new window

0
 
LVL 31

Expert Comment

by:Rob Henson
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 31

Accepted Solution

by:
Rob Henson earned 500 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Closing Comment

by:dnldsn
ID: 39946013
Rob

Nicely done. Thanks
0
 

Author Comment

by:dnldsn
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)
    Select Case Target.Address
        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 31

Expert Comment

by:Rob Henson
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

by:dnldsn
ID: 39946762
Rob

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

Thanks again.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now