Macro to unhide a sheet based on selection from drop-down menu

JacqH

New Member
Joined
Mar 3, 2016
Messages
2
I have a drop-down menu on the sheet called "Start" in cell D7 where a user can choose his/her name. When the user selects his/her name from that menu, I want a hidden sheet to appear after he/she types the password (the sheet holds personal information of the user). The password is checked against the value in cell D10 on the "Start" sheet.
In the dropdwon list there are blank cells.


There will essentially be approx 40 choices in that drop-down menu, and subsequently, 40 hidden sheets to accompany those choices (each sheet is exactly named as the name in the dropdon list).

When the user saves the workbook and closes it, a macro is hiding the sheet again.

Untill now I have the following code, but I do not get it to work and I do not get the password sub included in it.

Thanks in advance!

The code I have is:
XXXXX1 is the name of the person out of the dropdown list


-------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
Dim ws As Worksheet
' Set Target Range
Set rng = Target.Parent.Range("D7")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Exit if the Data Validation cell is blank
If Target.Value = "" Then Exit Sub
' Action if Condition(s) are met

Sub ViewSheet2()
pword = Application.InputBox("Type Password", "PASSWORD REQUIRED")
'If pword = "PASSWORD" Then
If pword = Range("D10").Value Then
Sheets("XXXXX1").Visible = True
End If
End Sub



For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Start" Then ws.Visible = xlSheetHidden
Next ws
' Sheets(Target.Value).Visible = True
With Sheets(Target.Value)
.Visible = True
.Activate
End With
End Sub


-------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Jan Mensen").Visible = xlVeryHidden
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Does someone know how to replace in sheets("XXXXX1") the XXXX1 with the name out of the dropdownbox?

Regards Jacques
 
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,335
Members
449,098
Latest member
thnirmitha

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