0% found this document useful (0 votes)
22 views

Excel Tips: VBA Code For Password For Dropdown List (Useful For Purchase Order)

The VBA code implements a password requirement for dropdown list selections in Excel. When a user selects a name from the dropdown list, the code prompts for a password associated with that name. If the correct password is entered, the selection remains. Otherwise, the cell is cleared. The sample code includes predefined passwords for names like Mike, Alan, Bob, and Pete to demonstrate the functionality.

Uploaded by

phaiz_nova874639
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Excel Tips: VBA Code For Password For Dropdown List (Useful For Purchase Order)

The VBA code implements a password requirement for dropdown list selections in Excel. When a user selects a name from the dropdown list, the code prompts for a password associated with that name. If the correct password is entered, the selection remains. Otherwise, the cell is cleared. The sample code includes predefined passwords for names like Mike, Alan, Bob, and Pete to demonstrate the functionality.

Uploaded by

phaiz_nova874639
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Excel Tips:

VBA Code for Password for Dropdown List (Useful for Purchase Order)

Basically, this is useful for people who needs a purchase order to come up with a unique password for
each name for listed in the "Requester” (or anything for that matter). Only RELEVANT for dropdown
list. Therefore you have to create a dropdown list for the “Requester”. The code is written in such a
way whenever you click on it, it will prompt you to enter password.Different names requires different
password, otherwise it will return as a blank cell.

To implement this, use shotcut key Alt+F11 when in excel to launch VBA. Sample names Mike,
Alan,Bob and Pete is used to simulate the case. Feel free to change the name and password.

VBA code:
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

You might also like