Showing form labels based on sheet contents

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?

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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I'm pretty sure the problem is with the calculation inside the Controls (here here) parentheses. I played around significantly with various versions, but nothing seems to work. You guys have saved me a million times. Any luck this time?
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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