How do I password protect a drop down list

pattigander

New Member
Joined
Jun 20, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I am trying to password protect each item in a drop down list. I found on a forum VBA code but need to understand it so I can edit it and use it with different names in the dropdown and in different locations. Below is the code. If someone can explain how to modify it I would be grateful or if you are a consultant and can provide assistance for a fee.

Option Explicit
Const Mike As String = "Mike1"
Const Alan As String = "Alan1"
Const Bob As String = "Bob1"
Const Pete As String = "Pete1"

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim pwd As String
Dim Oops As Boolean

Application.EnableEvents = False

For Each cell In Target
If Not Intersect(cell, Range("B7")) Is Nothing And cell <> "" Then
pwd = Application.InputBox("Password for " & cell & ":", _
"Enter Password", Type:=2)
Select Case cell.Value
Case "Mike"
If pwd <> Mike Then Oops = True
Case "Bob"
If pwd <> Bob Then Oops = True
Case "Alan"
If pwd <> Alan Then Oops = True
Case "Pete"
If pwd <> Pete Then Oops = True
End Select

If Oops Then
MsgBox "Bad password"
cell = ""
End If
End If
Next cell

Application.EnableEvents = True
End Sub
 
I have sheet1 with cell b7 as the cell for the name being taken from sheet2 using the data validation list function. I put in the code and it doesn't ask for a password. I am clearly doing something wrong...
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe somehow Application.EnableEvents got turn off?
Try running this code first:
VBA Code:
Sub try()
      Application.EnableEvents = True
End Sub
 
Upvote 0
I am not having any luck with this... nt recommendations? I appreciate all your help...
Patti
 
Upvote 0
Could you upload a sample workbook (without sensitive data) to a sharing site like dropbox.com or google drive?
And then share the link here.
 
Upvote 0
Here is the link to the sheet. I highlighted a cell that I would want to have a drop-down list of names and a password assigned.... Not drop down or password created so anything added is fine for the test application. I appreciate your help... please let me know if you are able to access the link. If not, I'd be happy to email you the form...

 
Upvote 0
Try this:
 
Upvote 0
Please do not put your email address in your posts, as spam bots regularly patrol sites like this looking for email addresses.
 
Upvote 0

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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
Back
Top