回答編集履歴
2
コード修正
answer
CHANGED
@@ -26,10 +26,6 @@
|
|
26
26
|
End If
|
27
27
|
End Sub
|
28
28
|
|
29
|
-
Private Sub ComboBox1_Change()
|
30
|
-
Debug.Print ComboBox1.Text
|
31
|
-
End Sub
|
32
|
-
|
33
29
|
Private Sub ComboBox2_AfterUpdate()
|
34
30
|
Dim dicList2 As Dictionary
|
35
31
|
Set dicList2 = dicList(Me.ComboBox1.Text)
|
@@ -41,16 +37,13 @@
|
|
41
37
|
End If
|
42
38
|
End Sub
|
43
39
|
|
44
|
-
|
45
40
|
Private Sub UserForm_Initialize()
|
46
41
|
Dim aryData()
|
47
42
|
With Worksheets("DataSheet").Range("A1").CurrentRegion
|
48
43
|
aryData = .Offset(1, 1).Resize(.Rows.Count - 1, 3).Value
|
49
44
|
End With
|
50
|
-
|
51
45
|
|
52
|
-
Set dicList = New Dictionary
|
46
|
+
Set dicList = New Dictionary
|
53
|
-
|
54
47
|
Dim i As Long
|
55
48
|
For i = 1 To UBound(aryData)
|
56
49
|
Dim dicList2 As Dictionary
|
@@ -66,8 +59,7 @@
|
|
66
59
|
Else
|
67
60
|
Set dicList3 = New Dictionary
|
68
61
|
End If
|
69
|
-
dicList3(CStr(aryData(i, 3))) = aryData(i, 3)
|
62
|
+
dicList3(CStr(aryData(i, 3))) = aryData(i, 3)
|
70
|
-
|
71
63
|
Set dicList2(CStr(aryData(i, 2))) = dicList3
|
72
64
|
Set dicList(CStr(aryData(i, 1))) = dicList2
|
73
65
|
Next
|
1
説明の改善
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
ユーザーフォームのInitializeイベントで、ComboBox1用のDictionaryのアイテムにComboBox2用のDictionary、さらにComboBox2用のDictionaryのアイテムにComboBox3用のDictionaryを格納するという、入れ子構造にして、全てのコンボボックスのリストデータを格納するようにしました。
|
8
8
|
|
9
|
-
ComboBox1、ComboBox2のAfterUpdateイベントでは、入れ子構造のDictionaryから
|
9
|
+
ComboBox1、ComboBox2のAfterUpdateイベントでは、入れ子構造のDictionaryからリストデータを取り出してコンボボックスのListに代入すればいいだけになります。
|
10
10
|
|
11
11
|
Changeイベントはコンボボックスで一文字入力したり削除しただけで発生します。AfterUpdateイベントだと入力し終わってから発生するので無駄がないです。
|
12
12
|
|