我在Excel VBA中遇到了ComboBox的问题。任何帮助都非常感谢。 这就是我想要做的事情:
我已经编写了下面的代码,但我得到一个空白的ComboBox_config_1。有人可以帮忙吗?提前谢谢!
Private Sub ComboBox_config_1_DropButtonClick()
Dim teil As Range
For Each teil In Tabelle1.Range("KonfiRange_1_1")
If teil.Value = ComboBox_groesse.Value Then
With Me.ComboBox_config_1
.AddItem teil.Value
End With
End If
Next teil
答案 0 :(得分:0)
我会将此操作放在ComboBox_groesse_Change事件中,如下所示:
Private Sub ComboBox_groesse_Change()
Dim rngFound As Range
Dim strFirst As String
Dim strList As String
Me.ComboBox_config_1.Clear
If Me.ComboBox_groesse.ListIndex = -1 Then Exit Sub 'Nothing selected
With Range("KonfiRange_1_1")
Set rngFound = .Find(Me.ComboBox_groesse.Text, .Cells(.Cells.Count), xlValues, xlWhole)
If Not rngFound Is Nothing Then
strFirst = rngFound.Address
Do
strList = strList & "|" & rngFound.Offset(, 1).Text
Set rngFound = .Find(Me.ComboBox_groesse.Text, rngFound, xlValues, xlWhole)
Loop While rngFound.Address <> strFirst
End If
End With
If Len(strList) > 0 Then Me.ComboBox_config_1.List = Split(Mid(strList, 2), "|")
Set rngFound = Nothing
End Sub