loop to check if visible

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
743
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
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,292
Office Version
365
Platform
Windows
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"
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,876
Office Version
365
Platform
Windows
@Av8tordude

In future please supply crosspost links, as per forum rules.
 

Watch MrExcel Video

Forum statistics

Threads
1,089,969
Messages
5,411,567
Members
403,379
Latest member
aarango

This Week's Hot Topics

Top