mrMozambique
Board Regular
- Joined
- Mar 9, 2005
- Messages
- 97
Hi all. I'm creating a type of Table of Contents form so users can easily scroll through my workbook that has multiple sheets. The ToC form only has label controls. Each label corresponds to a similarly named worksheet. The corresponding worksheet name has "ws" in front of it, but is otherwise the same (e.g. label = ARV, worksheet = wsARV). Sometimes the worksheets are hidden when the workbook loads based on the value in cell A1 of each worksheet (True or False). A macro evaluates A1 of each worksheet and hides those that have False.
So, what I'm trying to do is hide any labels in the form where their corresponding worksheets have False in cell A1. Note that I've renamed each sheet in the VBA properties menu to an acronym so it's no longer Sheet1, Sheet2, etc.
My code is doing nothing when the form loads. Any advice?
So, what I'm trying to do is hide any labels in the form where their corresponding worksheets have False in cell A1. Note that I've renamed each sheet in the VBA properties menu to an acronym so it's no longer Sheet1, Sheet2, etc.
My code is doing nothing when the form loads. Any advice?
Code:
Private Sub UserForm_Activate()
On Error Resume Next
Dim ws As Worksheet
For i = 0 To Worksheets.Count
If ws(i).Range("A1").Value = False Then
Controls(Right(ws(i).Name, Len(ws(i).Name) - 2)).Visible = False
Else
Controls(Right(ws(i).Name, Len(ws(i).Name) - 2)).Visible = True
End If
Next i
On Error GoTo 0
End Sub