VBA for multiple Worksheets

hezcal11

Board Regular
Joined
Jan 20, 2012
Messages
57
Hello, I have a workbook that allows 50 people to access their own page to input their monthly shift availability. The main page will have 50 boxes with names and a button next to each asking for a password to allow them to unhide their own page. The pages are numbered 1 to 50. Is there any way to do this without copying a macro 50 times changing the worksheet number for each. I was hoping there would be a 'lighter' way to achieve this.



NoNAMECONTACT NOPASSWORD
1 1 *

<COLGROUP><COL style="WIDTH: 20pt; mso-width-source: userset; mso-width-alt: 950" width=26><COL style="WIDTH: 109pt; mso-width-source: userset; mso-width-alt: 5302" width=145><COL style="WIDTH: 109pt; mso-width-source: userset; mso-width-alt: 5302" width=145><COL style="WIDTH: 109pt; mso-width-source: userset; mso-width-alt: 5302" width=145><TBODY>
</TBODY>

* The macro button is here​
Thanks

Colin
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You could perhaps do it with a "Change_Event" code
You would first need to uses a "Workbook_Event" to hide all sheets except "Master" (For input of password)
Using Sheet "Master" "D2" for input of "Password_to _Open", and "E2" for "Password_for Closing"
This coding means you only have to input any Password into "E2" for the reltive sheet to open.
NB:- You will perhaps also need to protect the code from other users. :- (VbWindow "Tools", VbProject Properties, Protection)

This is the first code that goes in the "ThisWorkbook" code module.

Code:
Option Explicit
Private Sub Workbook_Open()
Dim Sht As Worksheet
For Each Sht In Worksheets
    If Not Sht.Name = "Master" Then
        Sht.Visible = xlVeryHidden
    End If
Next Sht
End Sub

Then this is the code for "Worksheet_Change" event in sheet "Master.
You will need to change the "s" numbers for your passwords and add further sheets.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
Application.EnableEvents = False
If Target = Range("D2") Then
Select Case Target.Value
Case "s2": Sheets("Sheet2").Visible = True
Case "s3": Sheets("Sheet3").Visible = True
Case "s4": Sheets("Sheet4").Visible = True
Case "s5": Sheets("Sheet5").Visible = True
End Select
End If
If Target = Range("E2") Then
Select Case Target.Value
Case "s2": Sheets("Sheet2").Visible = xlVeryHidden
Case "s3": Sheets("Sheet3").Visible = xlVeryHidden
Case "s4": Sheets("Sheet4").Visible = xlVeryHidden
Case "s5": Sheets("Sheet5").Visible = xlVeryHidden
End Select
End If
Target.Value = "####"
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Yo.

Adapt accordingly.

Code:
Dim unhidesheet as integer
unhidesheet = ActiveSheet.Shapes(Application.Caller).topleftcell.offset(0, -3).value
 
Upvote 0
You could perhaps do it with a "Change_Event" code
You would first need to uses a "Workbook_Event" to hide all sheets except "Master" (For input of password)
Using Sheet "Master" "D2" for input of "Password_to _Open", and "E2" for "Password_for Closing"
This coding means you only have to input any Password into "E2" for the reltive sheet to open.
NB:- You will perhaps also need to protect the code from other users. :- (VbWindow "Tools", VbProject Properties, Protection)

This is the first code that goes in the "ThisWorkbook" code module.

Code:
Option Explicit
Private Sub Workbook_Open()
Dim Sht As Worksheet
For Each Sht In Worksheets
    If Not Sht.Name = "Master" Then
        Sht.Visible = xlVeryHidden
    End If
Next Sht
End Sub

Then this is the code for "Worksheet_Change" event in sheet "Master.
You will need to change the "s" numbers for your passwords and add further sheets.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
Application.EnableEvents = False
If Target = Range("D2") Then
Select Case Target.Value
Case "s2": Sheets("Sheet2").Visible = True
Case "s3": Sheets("Sheet3").Visible = True
Case "s4": Sheets("Sheet4").Visible = True
Case "s5": Sheets("Sheet5").Visible = True
End Select
End If
If Target = Range("E2") Then
Select Case Target.Value
Case "s2": Sheets("Sheet2").Visible = xlVeryHidden
Case "s3": Sheets("Sheet3").Visible = xlVeryHidden
Case "s4": Sheets("Sheet4").Visible = xlVeryHidden
Case "s5": Sheets("Sheet5").Visible = xlVeryHidden
End Select
End If
Target.Value = "####"
Application.EnableEvents = True
End If
End Sub

Thanks for that. Will try it out
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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