我根据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}}