PDA

View Full Version : Check if labels are visible



av8tordude
10-26-2019, 04:03 AM
I have a userform that has 10 labels that are named with the leading text lblM_ (see below). I want to check if any of these labels are visible. If any of the labels below are visible then "Do Stuff" else "Do Other Stuff"

I kindly ask for assistance with a vba code that can accomplish this task.

I posted similar posting here: https://www.mrexcel.com/forum/excel-questions/1113394-loop-check-if-visible.html

lblM_tbxSch800
lblM_tbxSch900
lblM_tbxSch1000
lblM_tbxSch1100
lblM_tbxSch1200
lblM_tbxSch1300
lblM_tbxSch1400
lblM_tbxSch1500
lblM_tbxSch1600

lblM_tbxSchNotes

SamT
10-26-2019, 06:43 PM
What code makes the labels visible or not visible?

snb
10-27-2019, 10:30 AM
If you rename the labels:

lblM_1
lblM_2
lblM_3
lblM_4
lblM_5
lblM_6
lblM_7
lblM_8
lblM_9
lblM_10



Sub M_snb()
for j=1 to 10
y=y+me("lblM_" & j).visible
next

msgbox "Do " & iif(y,"","other ") & "stuff"
End Sub

Kenneth Hobs
10-27-2019, 12:57 PM
You have an answer in the other forum. This one is my method.

Private Sub CommandButton1_Click()
MsgBox tfVisible
MsgBox sVisible
End Sub


Private Function tfVisible() As Boolean
Dim i As Integer
For i = 800 To 1600 Step 100
If Me("lblM_tbxSchNotes" & i).Visible = True Then
tfVisible = True
Exit Function
End If
Next i
If Me("lblM_tbxSchNotes").Visible = True Then tfVisible = True
End Function


Private Function sVisible() As String
Dim i As Integer
For i = 800 To 1600 Step 100
If Me("lblM_tbxSchNotes" & i).Visible = True Then
sVisible = "lblM_tbxSchNotes" & i
Exit Function
End If
Next i
If Me("lblM_tbxSchNotes").Visible = True Then sVisible = "lblM_tbxSchNotes"
End Function