基于另一个组合框的组合框中的唯一值

时间:2015-05-12 10:46:32

标签: excel excel-vba vba

我根据combobox3中的选择在combobox3成功添加了唯一值。但是,当我根据combobox2上的选择实现相同的代码以在combobox2.value中添加唯一值时,它无效。我将combobox3.value替换为B,将C列替换为Private Sub ComboBox1_Change() Dim Ws As Worksheet, _ Dic As Object, _ rCell As Range, _ Key As String Set Ws = Worksheets("Sheet1") Set Dic = CreateObject("Scripting.Dictionary") Me.ComboBox2.Clear 'Clear all previously added elements Me.ComboBox2.Value = vbNullString 'Set active value as an empty string '------Here is where you need to do your tests------- For Each rCell In Ws.Range("B2", Ws.Cells(Rows.Count, "B").End(xlUp)) If rCell.Offset(0, -1) <> Me.ComboBox1.Value Then Else If Not Dic.exists(LCase(rCell.Value)) Then Dic.Add LCase(rCell.Value), Nothing End If End If Next rCell For Each Key In Dic UserForm1.ComboBox2.AddItem Key Next End Sub 列。

{{1}}

0 个答案:

没有答案