Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1852to1856
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Userform Einträge in Tabelle ausfiltern

Userform Einträge in Tabelle ausfiltern
07.11.2021 12:38:30
Thomas
Guten Tag miteinander.
Ich versuche eine Userform zu bauen worin man über ein angeklicktes Kriterium in der ersten Combobox zur nächsten Combobox gelangt um dort das nächste Kriterium anzuklicken und das bis hin über 7 Comboboxen wo dann der ausgesuchte Artikel mit einer Artikelnummer in einer TextBox angezeigt wird. Damit will ich dann später eine Weiterverarbeitung machen. Aber die Verschachtelung mit den Comboboxen bringe ich nicht hin.
Ich habe für das Verständnis wie die Tabelle strukturell aussehen soll und wie die User Form aussehen soll in einer Datei angehängt. Da fehlt einfach noch die TextBox wo die Artikelnummer dann angezeigt wird.
Im Moment wäre ich ja nur schon froh wenn mir jemand einen Anstoss für so eine Verschachtelung geben könnte die auch funktioniert und es müssen auch nicht schon 7 Comboboxen programmiert werden, den Rest sollte ich selber hinkriegen.
Bin für Tipps, Anregungen, Lösungsvorschlägen sehr offen und dankbar.
Danke
Thomas
https://www.herber.de/bbs/user/148981.xlsm

13
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Nachfrage
07.11.2021 13:28:11
ralf_b
Hallo,
willst du die Datensätze nach jedem Kriterium filtern oder erst zu Schluß ein Ergebnis angezeigt bekommen?
Sind die Filterkriterien fix oder sollen die aus der aktuellen Datenbank erstellt werden?
Das es sich hier um Kabeltypen handelt, erkenne ich gerade noch.
Deine Aufgabe scheint so eine abhängige Dropdowngeschichte zu werden. Zumindest in Teilen. Also welche Werte der Spalten beziehen sich aufeinander und welche können ungefiltert in die Auswahlliste?
die einfachste Variante wäre eine feste Zuweisung.
Text1.list = Worksheets("Tabelle1").Range ("B7:B11").Value
Anzeige
AW: Nachfrage
07.11.2021 15:28:17
Thomas
Hallo Ralf danke für deine Antwort.
Also das ist so....
Gehen wir jetzt einfach mal von der Thematik Kabel aus dann muss man es so verstehen.
In der der ersten Combobox gebe ich Kabel ein, dann sollen in der zweiten Combobox die Kabeltypen erscheinen wie Cca, Dca, Eca, Pur Pur, TT, Td usw. da soll ich dann einer von diesen Typen auswählen können. In der 3. Combobox dann soll es möglich sein, ungeschirmt oder geschrimt auszuwählen, in der 4. Combobox dann die Aderzahl usw.
Woher die Daten kommen sollen: Ich stelle mir vor dass ich dieses in einer Tabelle strukturiere mit Spalte 1, Kabel (denn hier werden später mal noch andere Arten von Artikel zum auswählen sein wie etwa Schalter, Kanal, Trasse usw. Die dann auch weiter aufgefächert werden) . In der 2. Spalte sind dann die Kabel Typen abgelegt wie Cca, Dca, Eca usw. In der 3. Spalte lege ich geschirmt und ungeschirmt ab usw.
Mit dieser Struktur sollte es ja dann möglich sein immer nur das auswählen zu können was in dieser Tabelle auch abgelegt ist. Auf keinen fall will ich zuerst alle such Kriterien eingeben und dann suchen lassen weil das Problem ja besteht das ich so etwas suche was entweder mit falschen Kriterien gesucht wird oder etwas suche was gar nicht in der Tabelle abgelegt wäre.
Verstehst du jetzt in etwa wie ich das meine?
Anzeige
AW: Nachfrage
07.11.2021 16:59:48
Nepumuk
Hallo Thomas,
teste mal:

Option Explicit
Private mavntValues As Variant
Private Sub ComboBox1_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
For lngIndex = 2 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
If ComboBox1.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 2)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text Then _
Call ComboBox2.AddItem(mavntValues(ialngIndex, 2))
Next
End If
End Sub
Private Sub ComboBox2_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
For lngIndex = 3 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
If ComboBox2.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 3)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text Then Call ComboBox3.AddItem(mavntValues(ialngIndex, 3))
Next
End If
End Sub
Private Sub ComboBox3_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
For lngIndex = 4 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
If ComboBox3.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 4)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text Then _
Call ComboBox4.AddItem(mavntValues(ialngIndex, 4))
Next
End If
End Sub
Private Sub ComboBox4_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
For lngIndex = 5 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
If ComboBox4.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 5)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text Then Call ComboBox5.AddItem(mavntValues(ialngIndex, 5))
Next
End If
End Sub
Private Sub ComboBox5_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
For lngIndex = 6 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
If ComboBox5.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 6)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text And mavntValues(ialngIndex, 5) = ComboBox5.Text Then _
Call ComboBox6.AddItem(mavntValues(ialngIndex, 6))
Next
End If
End Sub
Private Sub ComboBox6_Change()
Dim ialngIndex As Long
If ComboBox6.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If mavntValues(ialngIndex, 1) = ComboBox1.Text And mavntValues(ialngIndex, 2) = ComboBox2.Text And _
mavntValues(ialngIndex, 3) = ComboBox3.Text And mavntValues(ialngIndex, 4) = ComboBox4.Text And _
mavntValues(ialngIndex, 5) = ComboBox5.Text And mavntValues(ialngIndex, 6) = ComboBox6.Text Then _
TextBox1.Text = mavntValues(ialngIndex, 7)
Next
End If
End Sub
Private Sub UserForm_Initialize()
Dim ialngIndex As Long
Dim objDictionary As Object
With Tabelle1
mavntValues = .Range(.Cells(7, 2), .Cells(.Cells(.Rows.Count, 2).End(xlUp).Row, 8)).Value2
End With
ReDim Preserve mavntValues(LBound(mavntValues, 1) To UBound(mavntValues, 1), LBound(mavntValues, 2) To 8)
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
mavntValues(ialngIndex, 8) = 6 + ialngIndex
If Not IsEmpty(mavntValues(ialngIndex, 1)) Then objDictionary(mavntValues(ialngIndex, 1)) = vbNullString
Next
ComboBox1.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Gruß
Nepumuk
Anzeige
AW: Nachfrage
07.11.2021 17:04:22
Nepumuk
Achso,
ich habe deine Controls zurück benannt, es ist meiner Meinung nach Unsinn deren Namen zu ändern.
Teste die Mappe: https://www.herber.de/bbs/user/148984.xlsm
Gruß
Nepumuk
AW: Nachfrage
07.11.2021 20:38:57
Thomas
Hallo Nepumuk, erst mal vielen Dank für deine tolle Leistung. Bin echt erstaunt!
Funktioniert soweit super. Das einzige was noch etwas holpert ist das mit den gleichen Zeilen Einträgen. ComboBox 2 und 3 listen den selben Text noch mehr mals auf. Kann man dagegen noch etwas machen?
Ja die Benennung der Elemente. Das ist halt nur mal zum ausprobieren. Deshalb die Vergewaltigung der Namen.
Gruss Thomas
Anzeige
AW: Nachfrage
07.11.2021 21:05:39
Nepumuk
Hallo Thomas,
so besser?

Option Explicit
Private mavntValues As Variant
Private Sub ComboBox1_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 2 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox1.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 2)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text Then _
objDictionary(mavntValues(ialngIndex, 2)) = vbNullString
Next
End If
ComboBox2.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Private Sub ComboBox2_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 3 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox2.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 3)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text Then objDictionary(mavntValues(ialngIndex, 3)) = vbNullString
Next
End If
ComboBox3.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Private Sub ComboBox3_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For lngIndex = 4 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
If ComboBox3.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 4)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text Then _
objDictionary(mavntValues(ialngIndex, 4)) = vbNullString
Next
End If
ComboBox4.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Private Sub ComboBox4_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 5 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox4.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 5)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text Then objDictionary(mavntValues(ialngIndex, 5)) = vbNullString
Next
End If
ComboBox5.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Private Sub ComboBox5_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 6 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox5.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 6)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text And mavntValues(ialngIndex, 5) = ComboBox5.Text Then _
objDictionary(mavntValues(ialngIndex, 6)) = vbNullString
Next
End If
ComboBox6.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Private Sub ComboBox6_Change()
Dim ialngIndex As Long
If ComboBox6.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If mavntValues(ialngIndex, 1) = ComboBox1.Text And mavntValues(ialngIndex, 2) = ComboBox2.Text And _
mavntValues(ialngIndex, 3) = ComboBox3.Text And mavntValues(ialngIndex, 4) = ComboBox4.Text And _
mavntValues(ialngIndex, 5) = ComboBox5.Text And mavntValues(ialngIndex, 6) = ComboBox6.Text Then _
TextBox1.Text = mavntValues(ialngIndex, 7)
Next
End If
End Sub
Private Sub UserForm_Initialize()
Dim ialngIndex As Long
Dim objDictionary As Object
With Tabelle1
mavntValues = .Range(.Cells(7, 2), .Cells(.Cells(.Rows.Count, 2).End(xlUp).Row, 8)).Value2
End With
ReDim Preserve mavntValues(LBound(mavntValues, 1) To UBound(mavntValues, 1), LBound(mavntValues, 2) To 8)
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
mavntValues(ialngIndex, 8) = 6 + ialngIndex
If Not IsEmpty(mavntValues(ialngIndex, 1)) Then objDictionary(mavntValues(ialngIndex, 1)) = vbNullString
Next
ComboBox1.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Gruß
Nepumuk
Anzeige
AW: Nachfrage
07.11.2021 21:24:52
Thomas
Hallo Nepumuk, ich weiß gar nicht was ich sagen soll?
Ganz tolle Sache die du da gemacht hast. Habe jetzt auch der ganze Nachmittag experimentiert und habe einige Lösungsansätze hingekriegt.
Aber wenn ich dein Skript ansehe, fällt mir auf, dass deines viel einfacher und wohl auch schneller wie auch Fehlerfrei läuft. Ich denke das könnte ich gebrauchen um mein Vorhaben weiter zu entwickeln, wenn das erlaubt ist?
Ich möchte jetzt nicht übertreiben oder frech werden. Aber so spontan würde mich eines noch interessieren. Gibt es etwa auch noch die Möglichkeit den Text in den Comboboxen sichtbar zu machen bevor man drauf klickt?
Ansonsten muss ich sagen Tip Top bin echt begeistert was du da gemacht hast.
Gruss
Thomas
Anzeige
AW: Nachfrage
08.11.2021 07:03:58
Nepumuk
Hallo Thomas,

Gibt es etwa auch noch die Möglichkeit den Text in den Comboboxen sichtbar zu machen bevor man drauf klickt?
Wie meinst du das? Eventuell die ComboBox2 aufklappen wenn in ComboBox1 eine Auswahl getroffen wurde?
Gruß
Nepumuk
AW: Nachfrage
08.11.2021 10:22:10
Thomas
Guten Morgen Nepumuk,
ja genau so in dieser Art. Oder einfach der erste Begriff in der Combo gleich aktiv. Ich versuchte es mit dem Befehl ComboBox2.Listindex = 0 aber da kommt plötzlich ein Fehler zum Beispiel dann wenn ich in der ersten Combo einen anderen Wert auswähle.
Gruss
Thomas
Anzeige
AW: Nachfrage
08.11.2021 11:00:04
Nepumuk
Hallo Thomas,
teste mal:

Option Explicit
Private mavntValues As Variant
Private mblnNoEvent As Boolean
Private Sub ComboBox1_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 2 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox1.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 2)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text Then _
objDictionary(mavntValues(ialngIndex, 2)) = vbNullString
Next
End If
With ComboBox2
.List = objDictionary.Keys
mblnNoEvent = True
.ListIndex = 0
mblnNoEvent = False
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox2_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 3 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox2.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 3)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text Then objDictionary(mavntValues(ialngIndex, 3)) = vbNullString
Next
End If
With ComboBox3
.List = objDictionary.Keys
If Not mblnNoEvent Then
mblnNoEvent = True
If .ListCount > 0 Then .ListIndex = 0
mblnNoEvent = False
End If
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox3_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For lngIndex = 4 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
If ComboBox3.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 4)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text Then _
objDictionary(mavntValues(ialngIndex, 4)) = vbNullString
Next
End If
With ComboBox4
.List = objDictionary.Keys
If Not mblnNoEvent Then
mblnNoEvent = True
If .ListCount > 0 Then .ListIndex = 0
mblnNoEvent = False
End If
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox4_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 5 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox4.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 5)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text Then objDictionary(mavntValues(ialngIndex, 5)) = vbNullString
Next
End If
With ComboBox5
.List = objDictionary.Keys
If Not mblnNoEvent Then
mblnNoEvent = True
If .ListCount > 0 Then .ListIndex = 0
mblnNoEvent = False
End If
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox5_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 6 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox5.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 6)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text And mavntValues(ialngIndex, 5) = ComboBox5.Text Then _
objDictionary(mavntValues(ialngIndex, 6)) = vbNullString
Next
End If
With ComboBox6
.List = objDictionary.Keys
If Not mblnNoEvent Then
mblnNoEvent = True
If .ListCount > 0 Then .ListIndex = 0
mblnNoEvent = False
End If
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox6_Change()
Dim ialngIndex As Long
If ComboBox6.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If mavntValues(ialngIndex, 1) = ComboBox1.Text And mavntValues(ialngIndex, 2) = ComboBox2.Text And _
mavntValues(ialngIndex, 3) = ComboBox3.Text And mavntValues(ialngIndex, 4) = ComboBox4.Text And _
mavntValues(ialngIndex, 5) = ComboBox5.Text And mavntValues(ialngIndex, 6) = ComboBox6.Text Then _
TextBox1.Text = mavntValues(ialngIndex, 7)
Next
End If
End Sub
Private Sub CommandButton1_Click()
Call Unload(Object:=Me)
End Sub
Private Sub UserForm_Initialize()
Dim ialngIndex As Long
Dim objDictionary As Object
With Tabelle1
mavntValues = .Range(.Cells(7, 2), .Cells(.Cells(.Rows.Count, 2).End(xlUp).Row, 8)).Value2
End With
ReDim Preserve mavntValues(LBound(mavntValues, 1) To UBound(mavntValues, 1), LBound(mavntValues, 2) To 8)
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
mavntValues(ialngIndex, 8) = 6 + ialngIndex
If Not IsEmpty(mavntValues(ialngIndex, 1)) Then objDictionary(mavntValues(ialngIndex, 1)) = vbNullString
Next
ComboBox1.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Gruß
Nepumuk
Anzeige
AW: Nachfrage
08.11.2021 18:06:09
Thomas
Guten Abend Nepumuk, Danke viel mals für dein Einsatz.
Wahrscheinlich muss ich das weg lassen. Oder es gibt noch ein weiteren Trick?
Wenn ich in Box 1 etwas auswähle zeigt es dann in Box zwei gleich etwas an. Aber die anderen Boxen bleiben leer obschon ja auch etwas wäre das angezeigt werden muss. So muss ich dann aber erst in Box3 etwas anklicken damit in Box4 dann gleich etwas angezeigt wird, usw.
Gruss
Thomas
AW: Nachfrage
08.11.2021 18:45:06
Nepumuk
Hallo Thomas,
ok, dann so:

Option Explicit
Private mavntValues As Variant
Private Sub ComboBox1_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 2 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox1.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 2)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text Then _
objDictionary(mavntValues(ialngIndex, 2)) = vbNullString
Next
End If
With ComboBox2
.List = objDictionary.Keys
.ListIndex = 0
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox2_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 3 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox2.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 3)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text Then objDictionary(mavntValues(ialngIndex, 3)) = vbNullString
Next
End If
With ComboBox3
.List = objDictionary.Keys
If .ListCount > 0 Then .ListIndex = 0
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox3_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For lngIndex = 4 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
If ComboBox3.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 4)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text Then _
objDictionary(mavntValues(ialngIndex, 4)) = vbNullString
Next
End If
With ComboBox4
.List = objDictionary.Keys
If .ListCount > 0 Then .ListIndex = 0
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox4_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 5 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox4.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 5)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text Then objDictionary(mavntValues(ialngIndex, 5)) = vbNullString
Next
End If
With ComboBox5
.List = objDictionary.Keys
If .ListCount > 0 Then .ListIndex = 0
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox5_Change()
Dim lngIndex As Long
Dim ialngIndex As Long
Dim objDictionary As Object
For lngIndex = 6 To 6
Call Controls("ComboBox" & CStr(lngIndex)).Clear
Next
TextBox1.Text = vbNullString
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
If ComboBox5.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If Not IsEmpty(mavntValues(ialngIndex, 6)) Then If mavntValues(ialngIndex, 1) = ComboBox1.Text And _
mavntValues(ialngIndex, 2) = ComboBox2.Text And mavntValues(ialngIndex, 3) = ComboBox3.Text And _
mavntValues(ialngIndex, 4) = ComboBox4.Text And mavntValues(ialngIndex, 5) = ComboBox5.Text Then _
objDictionary(mavntValues(ialngIndex, 6)) = vbNullString
Next
End If
With ComboBox6
.List = objDictionary.Keys
If .ListCount > 0 Then .ListIndex = 0
End With
Set objDictionary = Nothing
End Sub
Private Sub ComboBox6_Change()
Dim ialngIndex As Long
If ComboBox6.ListIndex > -1 Then
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
If mavntValues(ialngIndex, 1) = ComboBox1.Text And mavntValues(ialngIndex, 2) = ComboBox2.Text And _
mavntValues(ialngIndex, 3) = ComboBox3.Text And mavntValues(ialngIndex, 4) = ComboBox4.Text And _
mavntValues(ialngIndex, 5) = ComboBox5.Text And mavntValues(ialngIndex, 6) = ComboBox6.Text Then _
TextBox1.Text = mavntValues(ialngIndex, 7)
Next
End If
End Sub
Private Sub CommandButton1_Click()
Call Unload(Object:=Me)
End Sub
Private Sub UserForm_Initialize()
Dim ialngIndex As Long
Dim objDictionary As Object
With Tabelle1
mavntValues = .Range(.Cells(7, 2), .Cells(.Cells(.Rows.Count, 2).End(xlUp).Row, 8)).Value2
End With
ReDim Preserve mavntValues(LBound(mavntValues, 1) To UBound(mavntValues, 1), LBound(mavntValues, 2) To 8)
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
For ialngIndex = LBound(mavntValues, 1) To UBound(mavntValues, 1)
mavntValues(ialngIndex, 8) = 6 + ialngIndex
If Not IsEmpty(mavntValues(ialngIndex, 1)) Then objDictionary(mavntValues(ialngIndex, 1)) = vbNullString
Next
ComboBox1.List = objDictionary.Keys
Set objDictionary = Nothing
End Sub
Gruß
Nepumuk
Anzeige
AW: Nachfrage
08.11.2021 18:57:59
Thomas
Hallo Nepumuk,
ja so ist perfekt. Du scheinst unermüdlich zu sein :-) Ich muss jetzt mal all diese Befehle einmal nachsehen, es hat einige dabei die ich in der Kombination nicht kenne. Ich hätte also null Chance gehabt sowas zusammen zubauen. Aber wenigstens habe ich jetzt eine Lerngrundlage. Danke dir bestens Nepumuk!!!!

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige