loop to check if visible

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I have a userform that has multiple labels. 10 labels are named with the leading text lblM_ (see below). I want to check if any of these labels are visible. I kindly ask for assistance with a vba code to check if any of these labels are visible

lblM_tbxSch800
lblM_tbxSch900
lblM_tbxSch1000
lblM_tbxSch1100
lblM_tbxSch1200
lblM_tbxSch1300
lblM_tbxSch1400
lblM_tbxSch1500
lblM_tbxSch1600

lblM_tbxSchNotes
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this

goes in USERFORM module

Code:
    Const lbl = "lblM_tbx"
    Const list = "Sch800 Sch900 Sch1000 Sch1100 Sch1200 tbxSch1300 Sch1400 Sch1500 Sch1600 SchNotes"
    Dim L As Variant, Ctrl As Control, Vis As String
    For Each Ctrl In Me.Controls
        For Each L In Split(list)
            L = lbl & L
            If Ctrl.name = L Then
                If Ctrl.Visible Then Vis = Vis & vbCr & L
            End If
        Next L
    Next Ctrl
    If Vis = "" Then Vis = "none"
    MsgBox Vis, vbOKOnly, "VISIBLE Labels"
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,091
Members
452,542
Latest member
Bricklin

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