pattigander
New Member
- Joined
- Jun 20, 2023
- Messages
- 17
- Office Version
- 365
- Platform
- 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
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