Windows user name and password for authentication

tsawyer73

New Member
Joined
Mar 20, 2013
Messages
21
I'd like to protect a small area in the excel sheet. Example H45:M47 where the user should put his/her windows username and password as authentication method through a VBA userform window.

I'm not a VBA expert due to that fact the full step by step VBA code and setup will appreciate!

Thanks
 
Skip the userform, in sheet PR:
Code:
Option Explicit
Dim oRng As Range


Private Sub Worksheet_SelectionChange(ByVal Target As Range)


    If Not Intersect(Target, Range("H45:M47")) Is Nothing Then '''sets which cell(s) to work with
        'Use the above line to set a range of cells by changing ("A1") to your range say ("B4:D12")
        If Not isPermitted() Then
            MsgBox "You don't have permission to edit here"
            oRng.Select
        End If
    Else
        Set oRng = Target
    End If
    
    
End Sub


Function isPermitted() As Boolean
    If UBound(Filter(Application.Transpose(Sheets("MySecretSheet").Range("A1:A10").Value), Environ("username"))) = 0 Then isPermitted = True
End Function

Just have a list of people who can edit in a sheet named "MySecretSheet"
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Here you go.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim strResponse As String

If Not Intersect(Target, [H45:M47]) Is Nothing Then

    strResponse = InputBox("Hello " & Environ("username") & ". Please enter your password")
    
        If Not strResponse = "beancounter" Then '<==== choose whatever password you want here
        
            [A1].Select

            MsgBox "Naughty naughty. You are not allowed to change this cell through conventional means"
            
        End If
        
End If
End Sub
 
Upvote 0
Skip the userform, in sheet PR:
Code:
Option Explicit
Dim oRng As Range


Private Sub Worksheet_SelectionChange(ByVal Target As Range)


    If Not Intersect(Target, Range("H45:M47")) Is Nothing Then '''sets which cell(s) to work with
        'Use the above line to set a range of cells by changing ("A1") to your range say ("B4:D12")
        If Not isPermitted() Then
            MsgBox "You don't have permission to edit here"
            oRng.Select
        End If
    Else
        Set oRng = Target
    End If
    
    
End Sub


Function isPermitted() As Boolean
    If UBound(Filter(Application.Transpose(Sheets("MySecretSheet").Range("A1:A10").Value), Environ("username"))) = 0 Then isPermitted = True
End Function

Just have a list of people who can edit in a sheet named "MySecretSheet"


Where can I put this code?

Thanks
 
Upvote 0
It's ok, but the method looks like same as my original VBA which has got only 1 fix password instead of list of them :(

Your method is shorter but the password is fix. How can I add username specific password to the code?
 
Upvote 0
My code is nothing like yours. IT doesn't need a password since it is based purely on the user - why do you need them to enter a password when you already know who they are?
 
Upvote 0
My code is nothing like yours. IT doesn't need a password since it is based purely on the user - why do you need them to enter a password when you already know who they are?

I tried to use your code without any result :( it was doing nothing :( I don't know why sorry!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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