Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default use looping to update label

i want to use looping to update the label but i cannot. (as below code)
Thanks.

for i = 1 to 10
label(i).visible = false
next i
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default use looping to update label

If you named the labels nicely, you could rely on their names:

I named mine label1, label2, label3, ..., label10

Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("Label" & iCtr).Visible = False
Next iCtr


If you didn't know the number of labels, but still wanted to hide them all, you
could use:

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.Label Then
ctrl.Visible = False
End If
Next ctrl



leungkong wrote:

i want to use looping to update the label but i cannot. (as below code)
Thanks.

for i = 1 to 10
label(i).visible = false
next i


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Label Update IK Excel Discussion (Misc queries) 1 March 23rd 07 06:56 AM
Data Label Update IK Excel Discussion (Misc queries) 1 March 23rd 07 06:55 AM
Looping to update another sheet Billy B Excel Programming 1 June 12th 06 03:01 AM
update label or text box JT[_2_] Excel Programming 3 February 1st 05 08:25 PM
update Label and other component Maileen[_2_] Excel Programming 2 January 15th 05 09:40 PM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"