input cancel not working when using if statements

miket11

New Member
Joined
Apr 10, 2018
Messages
1
Hello,

I'm trying to use application.inputbox with nested if statement but something is going wrong.

So basically what I want done.

there will be a button on the spreadsheet that when pressed will run the macro. But I don't want just anyone to run the macro. so I want to make it password protected.

I'm trying to do this using an application.inputbox.

when the button is pressed the inputbox will popup asking for password, if correct password is pressed then the macro is executed. This part I'm able to do, the problem occurs when I try to add anymore to the if statement.

For example I'm trying to add that if incorrect password is entered so the inputbox pops up again that says incorrect password. and at this point I want them to be able to keep popping up until correct password is entered.

if I start using elseif statement than my cancel and close buttons don't work.

Here is the code I have so far.

Sub UserPasswordInput()
Dim userInput As String

userInput = Application.InputBox("Enter the Password to Generate Limits?")
If userInput = "password" Then
runs macro
Else: userInput = Application.InputBox("Incorrect Password")
If userInput = "password" Then
runs program
End If
End If
End Sub


this is where I left off, ive tried to play around inserting elseif and other options but non work.

with the code as it is now if the correct password is entered than macro runs.

and also if incorrect password is entered I get the other inputbox that says incorrect password.

problem here is when first inbox box pops up and no password is entered and if I press ok or cancel it takes me to the next inputbox that says "incorrect password"

So its someone annoying.

I want this to be just like any other password requiring inputbox.

where when asked for password the user can enter password or cancel. if wrong password is entered than it would prompt them that it was wrong and they can continue to try to enter the password or cancel at anytime.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How about
Code:
Sub UserPasswordInput()
   Dim userInput As String
   Dim PassOk As Boolean
   
   Do Until PassOk
      userInput = Application.InputBox("Enter the Password to Generate Limits, or click Cancel to quit?")
      If userInput = "False" Then Exit Sub
      If userInput = "pass" Then
         PassOk = True
         runs Macro
      End If
   Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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