I have a macro that hides / shows sheets in a workbook, but I have to change the macro every time I add or remove a sheet.
Is there a way to change the range from C2:C41 to end the macro at the last active cell in Col A.
In this example, A41 would be the last active sheet name in the range.
I have the names of all the sheets in Col A and in Col B, I have "hide" or "show".
I'd greatly appreciate it if someone could assist with the code to automate the range, so I don't have to manually edit it all the time.
Thanks
Is there a way to change the range from C2:C41 to end the macro at the last active cell in Col A.
In this example, A41 would be the last active sheet name in the range.
I have the names of all the sheets in Col A and in Col B, I have "hide" or "show".
VBA Code:
Sub Show_Hide()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Worksheets("Directory").Range("C2:C41").Cells
If c.Value = "Hide" Then
Sheets(c.Offset(, -2).Value).Visible = False
Else
Sheets(c.Offset(, -2).Value).Visible = True
End If
Next
Sheets("Directory").Select
Application.ScreenUpdating = True
End Sub
I'd greatly appreciate it if someone could assist with the code to automate the range, so I don't have to manually edit it all the time.
Thanks