Ok, so after some googling and trial and error, I think this is the class solution that Norie mentioned.. I don't fully understand this currently, but seems to work anyway.
To use this, you need to insert a class module in your VBA project -- right click > insert > class module
Code for userform module
'-- Userform code
Option Explicit
Dim ctCombo As clsCombo
Dim colCombo As Collection
Private Sub UserForm_Initialize()
Dim ctrl As Control
Set colCombo = New Collection
For Each ctrl In Me.Controls
If TypeName(ctrl) = "ComboBox" Then
Set ctCombo = New clsCombo
Set ctCombo.Combo = ctrl
colCombo.Add ctCombo
End If
Next
End Sub
Code for Class module
'-- Class code
Option Explicit
Public WithEvents Combo As msforms.ComboBox
Private Sub Combo_Change()
If Len(Combo) = 0 Then
UserForm1.Controls(Replace(Combo.Name, "mid", "mia")).Enabled = False
Else
UserForm1.Controls(Replace(Combo.Name, "mid", "mia")).Enabled = True
End If
End Sub
Private Sub Terminate()
Set Combo = Nothing
End Sub
Bookmarks