Run VBA code based on multiple passwords

Shak1980

New Member
Joined
Aug 5, 2014
Messages
19
Hi all,

I don't know if this is possible. I would like to run a VBA code but only if the correct password is entered. the below code helps me do this. However, what I'd like to do now is to have it check against a list of usernames and passwords. So bassically when you try and run the code by pressing a command buttion, it will with an input box asking for a username and will ask you to enter a password that is specific to that username based on a list on another worksheet. The username on the other worksheet is in column A and the password in column B. Can anyone amend the below code or come up witha new one.

I hope this makes sense and thanks in advance for your help.

Code:
Private Sub CommandButton2_Click()

    Dim Pass            As String
    Dim Prompt          As String
    Dim Title           As String
    Dim UserPass        As String
     
    Pass = "MyPassword"
    Prompt = "Enter the password to continue"
    Title = "Password Input"
    UserPass = InputBox(Prompt, Title)
    If UserPass <> Pass Then
        Prompt = "You have entered an incorrect password"
        Title = "Incorrect Passowd"
        MsgBox Prompt, vbCritical, Title
        Exit Sub
    End If

row_number = 0
Do
DoEvents
row_number = row_number + 1
item_in_review = Sheets("Forms Received").Range("A" & row_number)
    If item_in_review = Con1.Text Then
Reg2.Text = Sheets("Forms Received").Range("D" & row_number)
Reg3.Text = Sheets("Forms Received").Range("E" & row_number)
Reg125.Text = Sheets("Forms Received").Range("F" & row_number)
Reg4.Text = Sheets("Forms Received").Range("G" & row_number)
Reg5.Text = Sheets("Forms Received").Range("H" & row_number)
Reg6.Text = Sheets("Forms Received").Range("I" & row_number)
Reg7.Text = Sheets("Forms Received").Range("J" & row_number)
Reg8.Text = Sheets("Forms Received").Range("K" & row_number)
Reg9.Text = Sheets("Forms Received").Range("L" & row_number)

End If

Loop Until item_in_review = ""

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

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