Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Anzeige
Inhaltsverzeichnis

mehrspaltige ComboBox

Forumthread: mehrspaltige ComboBox

mehrspaltige ComboBox
18.08.2005 02:54:25
Tinu
Liebe Excel Kollegen
Ich kämpfe wieder mal gegen (oder mit) VBA
In einer UserForm möchte ich eine ComboBox in Abhängigkeit einer anderen ComboBox auffüllen. Dies klappt auch einwandfrei:
' ComboBox4 laden

Private Sub ComboBox3_Change()
Dim x As Long
Dim lz As Long
ComboBox4.Clear
With ThisWorkbook.Sheets("Sheet1")
lz = .Range("A65536").End(xlUp).Row
For x = 3 To lz
If (.Cells(x, 3)) = ComboBox3.Text Then
If WorksheetFunction.CountIf(.Range("E2:E" & x), .Cells(x, 5)) = 1 Then
If (.Cells(x, 5)) <> "0" Then
ComboBox4.AddItem .Cells(x, 5)
End If
End If
End If
Next
End With
End Sub

Nun möchte ich aber in dieser ComboBox nicht nur eine Spalte (.Cells(x, 5)) anzeigen, sondern drei Spalten, also .Cells(x, 5&6&7). Die ComboBox habe ich unter "Eigenschaften" schon als dreispaltig definiert.
Wie muss ich nun den Code abändern?
Für Euere Hilfe bin ich sehr dankbar!
Gruss
Tinu
Anzeige

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: mehrspaltige ComboBox
18.08.2005 10:07:24
Matthias
Hallo Tinu,

ComboBox4.AddItem .Cells(x, 5)
ComboBox4.List(.ListCount - 1, 1) = .Cells(x, 6)
ComboBox4.List(.ListCount - 1, 2) = .Cells(x, 7)

Gruß Matthias
AW: mehrspaltige ComboBox
18.08.2005 11:34:39
Tinu
Hallo Matthias
Danke für die rasche Antwort. Leider funktioniert's aber bei mir nicht. Der Code bleibt bei "ComboBox4.List....." mit einer Fehlermeldung hängen.
Was könnte da falsch sein?
Gruss
Tinu
Anzeige
AW: mehrspaltige ComboBox
18.08.2005 12:30:57
Tinu
Hi Matthias
Ich hab mit Deiner Hilfe die Lösung gefunden. Ich hab einfach einen eigenen List Counter gebaut:
' ComboBox4 laden

Private Sub ComboBox3_Change()
Dim x As Long
Dim lz As Long
Dim lcb As Integer
lcb = 0
ComboBox4.Clear
With ThisWorkbook.Sheets("Sheet1")
lz = .Range("A65536").End(xlUp).Row
For x = 3 To lz
If (.Cells(x, 3)) = ComboBox3.Text Then
If WorksheetFunction.CountIf(.Range("E2:E" & x), .Cells(x, 5)) = 1 Then
If (.Cells(x, 5)) <> "0" Then
ComboBox4.AddItem .Cells(x, 5)
ComboBox4.List(lcb, 1) = (.Cells(x, 6))
ComboBox4.List(lcb, 2) = (.Cells(x, 7))
ComboBox4.List(lcb, 3) = (.Cells(x, 8))
lcb = lcb + 1
End If
End If
End If
Next
End With
End Sub

nochmals besten Dank
Gruss
Tinu
Anzeige
AW: mehrspaltige ComboBox
18.08.2005 20:06:09
Matthias
Hallo Tinu,
sorry, mein Fehler. Ich hab erst einen With ... End With-Block verwendet, dann aber gemerkt, dass in deinem Code schon einer steht und ihn wieder entfernt - leider nicht vollständig:

ComboBox4.AddItem .Cells(x, 5)
ComboBox4.List(ComboBox4.ListCount - 1, 1) = .Cells(x, 6)
ComboBox4.List(ComboBox4.ListCount - 1, 2) = .Cells(x, 7)

Gruß Matthias
Anzeige
AW: mehrspaltige ComboBox
18.08.2005 23:41:40
Tinu
Hallo Matthias
Deine Lösung ist offensichtlich eleganter, als mein Workaround.
besten Dank
Tinu
Anzeige
Anzeige
Live-Forum - Die aktuellen Beiträge
Datum
Titel
14.05.2026 13:31:09
14.05.2026 09:50:42
13.05.2026 19:14:18