BrainDiseasee
New Member
- Joined
- Aug 30, 2023
- Messages
- 22
- Office Version
- 365
- Platform
- Windows
Hello,
I am working with a large workbook where a roster of people have a worksheet for every name. The goal is that i can divide this roster up in to teams or different ranges for each team. When a macro is activated it only shows the ws names that are equal the specified range in the selected macro. I have done something similar to this to create WS based on a a range of cells but i keep getting a mismatch error. Below is just a sample of the code i am trying to work with. Once again the goal is when the macro is activated to change the sheet visibilities to TRUE for all sheet names found in the range N2.END(xlDown)
Thanks in advance to anyone that can help.
Sub sheet_Vis()
Dim NameField As Range
Dim Mgr As Range
Dim WSheet As Worksheet
Dim WSheetFound As Boolean
Dim DataWSheet As Worksheet
Set DataWSheet = Worksheets("Data")
Set NameField = DataWSheet.Range("N2", DataWSheet.Range("N2").End(xlDown))
Application.ScreenUpdating = False
For Each Mgr In NameField
For Each WSheet In ThisWorkbook.Worksheets
If WSheet.Name = NameField Then
WSheetFound = True
WSheet.Visible = True
Exit For
Else
WSheetFound = False
WSheet.Visible = False
Application.ScreenUpdating = True
End If
Next WSheet
Next
End Sub
I am working with a large workbook where a roster of people have a worksheet for every name. The goal is that i can divide this roster up in to teams or different ranges for each team. When a macro is activated it only shows the ws names that are equal the specified range in the selected macro. I have done something similar to this to create WS based on a a range of cells but i keep getting a mismatch error. Below is just a sample of the code i am trying to work with. Once again the goal is when the macro is activated to change the sheet visibilities to TRUE for all sheet names found in the range N2.END(xlDown)
Thanks in advance to anyone that can help.
Sub sheet_Vis()
Dim NameField As Range
Dim Mgr As Range
Dim WSheet As Worksheet
Dim WSheetFound As Boolean
Dim DataWSheet As Worksheet
Set DataWSheet = Worksheets("Data")
Set NameField = DataWSheet.Range("N2", DataWSheet.Range("N2").End(xlDown))
Application.ScreenUpdating = False
For Each Mgr In NameField
For Each WSheet In ThisWorkbook.Worksheets
If WSheet.Name = NameField Then
WSheetFound = True
WSheet.Visible = True
Exit For
Else
WSheetFound = False
WSheet.Visible = False
Application.ScreenUpdating = True
End If
Next WSheet
Next
End Sub