Password from cell

KlausW

Active Member
Joined
Sep 9, 2020
Messages
453
Office Version
  1. 2016
Platform
  1. Windows
Hi I am using this VBA code found here on Mr. Excel to run a macro after I have entered the password. Now I would like the code to find the password in cell H1.
Some who can help, any help would be appreciated.
Best regards Klaus W


VBA Code:
Sub MPW()
Dim MyPassword
MyPassword = InputBox("Please enter password", "Password Prompt", "********")

'hardcode password
If MyPassword = "password" Then
    MsgBox "Access Granted", vbInformation, "Access"
    'call macro
    Exit Sub
Else
    MsgBox "Access denied", vbCritical, "Error"
    Exit Sub
End If
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
So instead of using an InputBox to enter a password you want to set the password according to the value in cell H1 ?

Change
Code:
MyPassword = InputBox("Please enter password", "Password Prompt", "********")
to
Code:
MyPassword = Range("H1").value
 
Upvote 0
No, I still want to use an Input Box to enter a password in and the correct code is in cell H1. And it must then be entered in an Input Box to run another VBA code. KW
 
Upvote 0
Code:
If MyPassword = Sheets("some sheet").Range("H1").value Then

I think is what you are looking for.
 
Upvote 0
Code:
If MyPassword = Sheets("some sheet").Range("H1").value Then

I think is what you are looking for.
Hi, I get this message after I rename the sheet and write the same code that I have in cell H1. Access denied. KW
 
Upvote 0
I think it's because I use numbers, if I use letters it works. Can it be changed so that you can use both parts. KW
 
Upvote 0
Try:

Code:
If CStr(MyPassword) = Cstr(Sheets("some sheet").Range("H1").value) Then
 
Upvote 0
Solution
Try:

Code:
If CStr(MyPassword) = Cstr(Sheets("some sheet").Range("H1").value) Then
Hi RoryA Just as it should be, thank you very much.
Good evening here from Denmark
With best regards
Klaus W
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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