Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
VBA Code:
Private Sub UserForm_Initialize()
For Each ctrl In Me.Controls
If TypeName(ctrl) = "ComboBox" Then
With ctrl
.List = Sheets("Employees").Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Value
End With
End If
Next
End Sub
VBA Code:
Private Sub ComboBox1_Change()
Dim cmbBxType As Object
For i = 1 To Me.ComboBox1.ListCount
For Each ctrl In Me.Controls
If TypeName(ctrl) = "ComboBox" Then
With Me.ActiveControl.ActiveControl.Text
Set cmbBxType = Me.ActiveControl.ActiveControl.Name
If Me.ActiveControl.ActiveControl.Text <> Me.ActiveControl.ActiveControl.List(i - 1) Then .AddItem cmbBxType.List(i - 1)
End With
End If
Next
Next
End Sub
Inside my form, I have a frame. Inside the frame there are two textboxes and 20 comboboxes. What I was trying to do was make the code under combobox1_Change dynamic. That way I wouldn't have reference each combobox by name. If this worked, I would of made into a Sub routine, so all I would have to do was call that subroutine for each combobox under its change event. However I get the error stated in the title when I
VBA Code:
Set cmbBxType = Me.ActiveControl.ActiveControl.Name
Last edited: