Unlock / clear cell if dropdown = Edit

Hi,

I have a range of cells (B31:B59) They have drop downs of "Delete", "No Change" or "Edit"


If B32 Edit is selected i want K31 to be first be unlocked (password "hello") and second have its contents cleared

Is there some code that can achieve this for me?

Thanks
Seamus2626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

etech0Commented:
I would be happy to help you, but I don't understand your question. Can you try rephrasing it in a more clear way, and/or providing a sample file?
0
Glenn RayExcel VBA DeveloperCommented:
This clearly needs a little more thinking through.

First, in order to provide the kind of protection you're requesting for the data in column K, the entire sheet must be password-protected, except for those cells you want regular entry, such as those in B31:B59.  However, if you had a method for prompting a user for a password in order to allow deletion of a related cell, by extension, the user will also know the sheet password and could then unprotect it at any time and bypass the security you're hoping to achieve.  So, you'll actually need TWO (2) passwords:  one for end-user use and another to actually protect/unprotect the sheet.

Second, you have three user options (No Change, Edit, Delete), and while you've stated the mechanics for allowing a related cell to be deleted, there still remains the need to allow a related cell to be edited (since "Edit" is an option).  This is trickier, since even if you prompt a user for a password to edit, this action would unlock the sheet completely, meaning that any part of the sheet could then be edited unless there is a separate set of code to capture/limit entry to the single, related cell in column K, after which, the sheet would be re-protected again.  As above, two different passwords are needed.

Here's the VBA code - called a Worksheet_Change event - that would accomplish this:
Option Explicit
Dim pw As String
Dim varValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B31:B59")) Is Nothing And Target.Rows.Count = 1 Then
        If Target.Value = "Delete" Then
            pw = InputBox("Enter password to delete.", "Password Required")
            If pw = "rumin8" Then
                Me.Unprotect Password:="obfuscate"
                Target.Offset(0, 9).ClearContents
                Me.Protect Password:="obfuscate"
            End If
        ElseIf Target.Value = "Edit" Then
            pw = InputBox("Enter password to edit.", "Password Required")
            If pw = "rumin8" Then
                varValue = InputBox("Enter new value:", "Edit Value")
                If varValue <> "" Then
                    Me.Unprotect Password:="obfuscate"
                    Target.Offset(0, 9).Value = varValue
                    Me.Protect Password:="obfuscate"
                End If
            End If
        End If
    End If
End Sub

Open in new window

I've created two passwords:  "rumin8" for users, and "obfuscate" for the sheet; you could obviously choose others.

I've attached an example file that demonstrates your requested behavior.  One thing that is immediately apparent is how cumbersome and painstaking any edits will become.  That may be your intended plan, but it could make it more difficult to manage than you might realize.  Play around with this and I think you'll see what I mean.

Let me know if you have any questions.

-Glenn
EE-Q-28500836.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rory ArchibaldCommented:
FYI, you could protect the sheet in the Workbook_Open event using the UserInterfaceOnly:=True argument and then the code can clear the relevant cell(s) without needing to unprotect the sheet.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Seamus2626Author Commented:
Hi guys, thanks for your responses, Glen your code is slick, and i will be using this code again!

I will repost my q as having thought it through, my requirements are slightly different, thanks!
0
Seamus2626Author Commented:
Hi guys, thanks for your responses, Glen your code is slick, and i will be using this code again!

I will repost my q as having thought it through, my requirements are slightly different, thanks!
0
Glenn RayExcel VBA DeveloperCommented:
@Rory...I didn't know about that option (i.e., UserInterfaceOnly).  That is very handy; thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

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.