|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
shengdingb 发表于 2014-2-7 00:23
发现个问题,名称和型号都可以对应,但是数量只能对应名称,能不能对应上面2者。
或者其实就对应型号就 ... - Dim d As Object
- Private Sub ComboBox1_Change()
- If ComboBox1.ListIndex = -1 Then Exit Sub
- ComboBox2.Clear
- ComboBox3.Clear
- ComboBox4.Clear
- ComboBox2.List = Split(d(ComboBox1.Value), ",")
- End Sub
- Private Sub ComboBox2_Change()
- If ComboBox2.ListIndex = -1 Then Exit Sub
- ComboBox3.Clear
- ComboBox4.Clear
- ComboBox3.List = Split(d(ComboBox1.Value & vbTab & ComboBox2.Value), ",")
- End Sub
- Private Sub ComboBox3_Change()
- If ComboBox3.ListIndex = -1 Then Exit Sub
- ComboBox4.Clear
- ComboBox4.List = Split(d(ComboBox1.Value & vbTab & ComboBox2.Value & vbTab & ComboBox3.Value), ",")
- End Sub
- Private Sub CommandButton1_Click()
- Unload UserForm1
- End Sub
- Private Sub UserForm_Initialize()
- Dim arr, i&
- Set d = CreateObject("scripting.dictionary")
- arr = Sheet5.Range("a1").CurrentRegion
- For i = 1 To UBound(arr)
- s = arr(i, 1)
- If Not d.Exists(s) Then
- d(s) = arr(i, 2)
- Else
- If InStr("," & d(s) & ",", "," & arr(i, 2) & ",") = 0 Then d(s) = d(s) & "," & arr(i, 2)
- End If
- s = s & vbTab & arr(i, 2)
- If Not d.Exists(s) Then
- d(s) = arr(i, 3)
- Else
- If InStr("," & d(s) & ",", "," & arr(i, 3) & ",") = 0 Then d(s) = d(s) & "," & arr(i, 3)
- End If
- s = s & vbTab & arr(i, 3)
- If Not d.Exists(s) Then
- d(s) = arr(i, 4)
- Else
- If InStr("," & d(s) & ",", "," & arr(i, 4) & ",") = 0 Then d(s) = d(s) & "," & arr(i, 4)
- End If
- Next
- ComboBox1.List = Filter(d.Keys, vbTab, False)
- End Sub
复制代码 |
|