View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robert ap Rhys Robert ap Rhys is offline
external usenet poster
 
Posts: 21
Default Grouping controls


"Mats Samson" wrote in message
...
Is it possible to group specific controls from other controls of the same
type in a Userform? I cannot use a Frame because the controls are in
different locations in the form! Let's say that I want to set a specific
bunch of labels with red forecolour when a certain condition is met

(pressing
a button f.i.) but all the other labels stay
with black forecolour. Another issue would be to disable a bunch of
Textboxes that
are not related to the current task in the UserForm.
I tried to manipulate their Name, ex. ALabel1, BLabel1, ALabel2,
BLabel2....etc.
and then refer to the names as group of controls, but I'm not certain how

to
accomplish this, so I better ask you experts out there!


Using a naming convention:

I added three textboxes to a form and called them txtAName, txtAAddress and
txtBAge. Then I created the following test routine.

Private Sub CommandButton1_Click()
Dim obj As Control
Dim objT As MSForms.TextBox
For Each obj In Me.Controls
If TypeOf obj Is MSForms.TextBox Then
If Left(obj.Name, 4) = "txtA" Then
Set objT = obj
objT.BackColor = vbYellow
End If
End If
Next
End Sub

Works fine for me.

Robert