How do I password protect a drop down selection?

suzette0735

New Member
Joined
Jul 12, 2023
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I have a drop down list for different departments and each show different information. I want to password protect the "Accounting Copy" selection so that only the accounting department can see all the costs and mark up info. Is there a way to do this?
Thank you!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
It's possible with VBA, but you'd need to password protect your macro as well otherwise it would be easy to 'crack' the protection. Stage 1 would be a worksheet change event macro in the sheet code area of the sheet with the dropdown (right-click the sheet tab name, select View Code, and paste the code into the window that appears on the right of the screen). Adjust the cell reference of the dropdown, and the actual password required.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("A1"), Target) Is Nothing Then   '<-- *** Change "A1" to your dropdown cell
        If Not Target.Value = "Accounting Copy" Then Exit Sub
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        p = Application.InputBox("Enter the password")
        If p <> "password" Then Application.Undo            '<-- *** Change "password" to your actual password
        Application.EnableEvents = True
    End If
End Sub

Stage 2 is to password protect your code:
In the VBA Editor select Tools/VBAProject Properties/Protection tab.
Check the Lock project for viewing box
Enter & confirm password (whatever password you like, doesn't have to be the same as in the above code)
Click OK

When you save the file as macro-enabled, the next time you open the file you will be asked for a password to view the code (and as such, see what the Accounting Copy password has been set as).
 
Upvote 0
It's possible with VBA, but you'd need to password protect your macro as well otherwise it would be easy to 'crack' the protection. Stage 1 would be a worksheet change event macro in the sheet code area of the sheet with the dropdown (right-click the sheet tab name, select View Code, and paste the code into the window that appears on the right of the screen). Adjust the cell reference of the dropdown, and the actual password required.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("A1"), Target) Is Nothing Then   '<-- *** Change "A1" to your dropdown cell
        If Not Target.Value = "Accounting Copy" Then Exit Sub
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        p = Application.InputBox("Enter the password")
        If p <> "password" Then Application.Undo            '<-- *** Change "password" to your actual password
        Application.EnableEvents = True
    End If
End Sub

Stage 2 is to password protect your code:
In the VBA Editor select Tools/VBAProject Properties/Protection tab.
Check the Lock project for viewing box
Enter & confirm password (whatever password you like, doesn't have to be the same as in the above code)
Click OK

When you save the file as macro-enabled, the next time you open the file you will be asked for a password to view the code (and as such, see what the Accounting Copy password has been set as).
Thank you so much for your quick reply! This is awesome!! So glad it is possible and for your help! I am very new to VBA and I had already input a worksheet change for the drop downs. Is there a way to have both or maybe I did not do the drop downs correctly? Here are both codes I just tried to do but received an error:
1694428293564.png
 
Upvote 0
I can't test this, because I don't have access to your other modules (selectsheet etc.) but try this on a copy of your workbook:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("F2"), Target) Is Nothing Then
        Application.EnableEvents = False
        Select Case Target.Value
            Case "Select Sheet": selectsheet
            Case "Estimate/Bid Sheet": estimatebidsheet
            Case "Warehouse/Installer Copy": warehouseinstaller
            Case "Accounting Copy"
                Application.ScreenUpdating = False
                p = Application.InputBox("Enter the password")
                If p <> "LOGANAVERY" Then
                    Application.Undo
                    Application.EnableEvents = True
                    Exit Sub
                Else
                    accting
                End If
        End Select
        Application.EnableEvents = True
    End If
End Sub
 
Last edited:
Upvote 1
Solution
I can't test this, because I don't have access to your other modules (selectsheet etc.) but try this on a copy of your workbook:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("F2"), Target) Is Nothing Then
        Application.EnableEvents = False
        Select Case Target.Value
            Case "Select Sheet": selectsheet
            Case "Estimate/Bid Sheet": estimatebidsheet
            Case "Warehouse/Installer Copy": warehouseinstaller
            Case "Accounting Copy"
                Application.ScreenUpdating = False
                p = Application.InputBox("Enter the password")
                If p <> "LOGANAVERY" Then Application.Undo
                    Application.EnableEvents = True
                    Exit Sub
                Else
                    accting
                End If
        End Select
        Application.EnableEvents = True
    End If
End Sub
This is what popped up:
1694429282233.png
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,628
Members
452,661
Latest member
Nonhle

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