|
コンボボックスの数、
ComboBox1〜ComboBox4
の4個。
別の書き方もあると思いますが....。
っていうか、わざわざクラスにするとめんどいかも。
クラスモジュール(名前は、Class1)
Public WithEvents ComboBoxChangeEvent As MSForms.ComboBox
Private Sub ComboBoxChangeEvent_Change()
Dim CBnm As String, ACOj As String, i As Long
CBnm = ComboBoxChangeEvent.Name
With UserForm1
ACOj = .ActiveControl.Name
If CBnm <> ACOj Then Exit Sub
'MsgBox CBnm & vbLf & .Controls(CBnm).Value
For i = 1 To 4
If CBnm <> "ComboBox" & i Then
.Controls("ComboBox" & i).Value = .Controls(CBnm).Value
End If
Next
End With
End Sub
フォームモジュール(名前は、UserForm1)
Dim ComboCls() As New Class1
Private Sub UserForm_Initialize()
Dim i As Long
ComboBox1.List = Range("A1:A5").Value
ComboBox2.List = Range("B1:B5").Value
ComboBox3.List = Range("C1:C5").Value
ComboBox4.List = Range("D1:D5").Value
ReDim ComboCls(1 To 4)
For i = 1 To 4
Controls("ComboBox" & i).Value = i
Set ComboCls(i).ComboBoxChangeEvent = Controls("ComboBox" & i)
Next
End Sub
|
|