View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] imageswords.br@gmail.com is offline
external usenet poster
 
Posts: 14
Default use looping to update label

Hi Leungkong,
There is no "label" collection.
I assume that your labels are on a userform.
You need to loop throught the Controls collection of your Userform and
by using the .Item property. This uses base 0. So to loop through 10
labels your loop should be from 0 to 9. Then test each control to see
if it is a label. If it is then do whatever you want.
You could also user the Userform.Controls.Count property so you dont
have to change your loop if you add more labels.
Hope this is what you were looking for.

Kind regards

Bernie Russell

-------------------------------------------------------------------
Private Sub UpdateLabels()

On Error GoTo Err_UpdateLabels
Dim i As Integer
With UserForm1.Controls
For i = 0 To 9 'Alternatively Userform.Controls.Count -1
If (TypeOf .Item(i) Is MSForms.Label) = True Then .Item(i).Visible =
False
'If (TypeOf .Item(i) Is MSForms.Label) = True Then .Item(i).Visible
= True
Next i
End With
Err_UpdateLabels:
Debug.Print Err.Description
End Sub