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

Forumthread: Listbox einer UF mit bestimmten Werten füllen

Listbox einer UF mit bestimmten Werten füllen
17.09.2014 11:07:04
Dirk
Guten Morgen ins Forum,
ich hoffe, daß mir jemand weiter helfen kann.
Ich möchte eine Listbox, die mehr als 10 Spalten hat mit Daten füllen.
Bis hierhin kein Problem (siehe Code). Es sollen aber nur die Werte an-
gezeigt werden, die in Spalte A dem Inhalt einer Textbox entsprechen.
In der Praxis : Spalte A = Kundennummer, Zeilen = Fahrzeugdaten; hierbei
können mehrere Fahrzeuge einer Kundennummer entsprechen.
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False 'flackern abschalten
Dim AppExcel  As Object
Dim Pfad      As String
Dim Datei     As String
Dim arrWerte  As Variant
Pfad = "W:\Omni_KFZ\"
Datei = "PFV_Liste_kpl.xlsm"
ListBox1.ColumnCount = 30
ListBox1.ColumnWidths = "2cm;4cm;3cm;4cm;1cm;1,5cm;4cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm;2cm; _
4cm;0cm;2cm;2cm"
Set AppExcel = GetObject(Pfad & Datei)
arrWerte = AppExcel.Sheets("Liste").[A2:AD1000]
ListBox1.List = arrWerte
AppExcel.Close False
Set AppExcel = Nothing
Application.ScreenUpdating = True
End Sub
Private Sub ListBox1_Change()
If ListBox1.Tag  "" Then Exit Sub
T0 = ListBox1.List(ListBox1.ListIndex, 0)
T1 = ListBox1.List(ListBox1.ListIndex, 1)
T2 = ListBox1.List(ListBox1.ListIndex, 2)
T3 = ListBox1.List(ListBox1.ListIndex, 3)
T4 = ListBox1.List(ListBox1.ListIndex, 4)
T5 = ListBox1.List(ListBox1.ListIndex, 5)
T6 = ListBox1.List(ListBox1.ListIndex, 6)
T7 = ListBox1.List(ListBox1.ListIndex, 7)
T8 = ListBox1.List(ListBox1.ListIndex, 8)
T9 = ListBox1.List(ListBox1.ListIndex, 9)
T10 = ListBox1.List(ListBox1.ListIndex, 10)
T11 = ListBox1.List(ListBox1.ListIndex, 11)
T12 = ListBox1.List(ListBox1.ListIndex, 12)
T13 = ListBox1.List(ListBox1.ListIndex, 13)
T14 = ListBox1.List(ListBox1.ListIndex, 14)
T15 = ListBox1.List(ListBox1.ListIndex, 15)
T16 = ListBox1.List(ListBox1.ListIndex, 16)
T17 = ListBox1.List(ListBox1.ListIndex, 17)
T18 = ListBox1.List(ListBox1.ListIndex, 18)
T19 = ListBox1.List(ListBox1.ListIndex, 19)
T20 = ListBox1.List(ListBox1.ListIndex, 20)
T21 = ListBox1.List(ListBox1.ListIndex, 21)
T22 = ListBox1.List(ListBox1.ListIndex, 22)
T23 = ListBox1.List(ListBox1.ListIndex, 23)
T24 = ListBox1.List(ListBox1.ListIndex, 24)
T25 = ListBox1.List(ListBox1.ListIndex, 25)
T26 = ListBox1.List(ListBox1.ListIndex, 26)
T27 = ListBox1.List(ListBox1.ListIndex, 27)
T28 = ListBox1.List(ListBox1.ListIndex, 28)
T29 = ListBox1.List(ListBox1.ListIndex, 29)
End Sub

Anzeige

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Listbox einer UF mit bestimmten Werten füllen
17.09.2014 12:20:22
fcs
Hallo Dirk,
mit Vorgabe der Kunden-Nr. in einer Textbox kann es etwa wie folgt aussehen.
Beachte, dass das die Variable arrWerte nicht mehr in der Initialisierungs-Prozedur deklariert wird, sondern übergeordnet für das Userform-Modul.
Gruß
Franz
Option Explicit
Private arrWerte  As Variant
Private Sub prcUpdateListbox1(varKndNr)
Dim Zeile As Long, Spalte As Long, Zeile_L As Long
Dim arrListe() As Variant
'anzahl Treffer ermitteln
Zeile_L = 0
For Zeile = LBound(arrWerte, 1) To UBound(arrWerte, 1)
If varKndNr = arrWerte(Zeile, 1) Then Zeile_L = Zeile_L + 1
Next
ListBox1.Clear
If Zeile_L > 0 Then
ReDim arrListe(1 To Zeile_L, LBound(arrWerte, 2) To UBound(arrWerte, 2))
Zeile_L = 0
For Zeile = LBound(arrWerte, 1) To UBound(arrWerte, 1)
If varKndNr = arrWerte(Zeile, 1) Then
Zeile_L = Zeile_L + 1
For Spalte = LBound(arrWerte, 2) To UBound(arrWerte, 2)
arrListe(Zeile_L, Spalte) = arrWerte(Zeile, Spalte)
Next
End If
Next
ListBox1.List = arrListe
Erase arrListe
Else
MsgBox "Keine Daten zur Kunden-Nummer"
End If
End Sub
Private Sub TextBox_KndNr_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Textbox zur Eingabe der Kundennummer, deren Daten angezeigt werden sollen
ListBox1.Tag = "X"
If Me.TextBox_KndNr  "" Then
Call prcUpdateListbox1(IIf(IsNumeric(Me.TextBox_KndNr), _
Val(Me.TextBox_KndNr), Me.TextBox_KndNr))
Else
ListBox1.List = arrWerte
End If
ListBox1.Tag = ""
End Sub
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False 'flackern abschalten
Dim AppExcel  As Object
Dim Pfad      As String
Dim Datei     As String
Pfad = "W:\Omni_KFZ\"
Pfad = "D:\Test\"
Datei = "PFV_Liste_kpl.xlsm"
ListBox1.ColumnCount = 30
ListBox1.ColumnWidths = "2cm;4cm;3cm;4cm;1cm;1,5cm;4cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm;" _
& "0cm;2cm;4cm;0cm;2cm;2cm"
Set AppExcel = GetObject(Pfad & Datei)
arrWerte = AppExcel.Sheets("Liste").[A2:AD1000]
ListBox1.List = arrWerte
AppExcel.Close False
Set AppExcel = Nothing
Application.ScreenUpdating = True
End Sub
Private Sub ListBox1_Change()
If ListBox1.Tag  "" Then Exit Sub
T0 = ListBox1.List(ListBox1.ListIndex, 0)
T1 = ListBox1.List(ListBox1.ListIndex, 1)
T2 = ListBox1.List(ListBox1.ListIndex, 2)
T3 = ListBox1.List(ListBox1.ListIndex, 3)
T4 = ListBox1.List(ListBox1.ListIndex, 4)
T5 = ListBox1.List(ListBox1.ListIndex, 5)
T6 = ListBox1.List(ListBox1.ListIndex, 6)
T7 = ListBox1.List(ListBox1.ListIndex, 7)
T8 = ListBox1.List(ListBox1.ListIndex, 8)
T9 = ListBox1.List(ListBox1.ListIndex, 9)
T10 = ListBox1.List(ListBox1.ListIndex, 10)
T11 = ListBox1.List(ListBox1.ListIndex, 11)
T12 = ListBox1.List(ListBox1.ListIndex, 12)
T13 = ListBox1.List(ListBox1.ListIndex, 13)
T14 = ListBox1.List(ListBox1.ListIndex, 14)
T15 = ListBox1.List(ListBox1.ListIndex, 15)
T16 = ListBox1.List(ListBox1.ListIndex, 16)
T17 = ListBox1.List(ListBox1.ListIndex, 17)
T18 = ListBox1.List(ListBox1.ListIndex, 18)
T19 = ListBox1.List(ListBox1.ListIndex, 19)
T20 = ListBox1.List(ListBox1.ListIndex, 20)
T21 = ListBox1.List(ListBox1.ListIndex, 21)
T22 = ListBox1.List(ListBox1.ListIndex, 22)
T23 = ListBox1.List(ListBox1.ListIndex, 23)
T24 = ListBox1.List(ListBox1.ListIndex, 24)
T25 = ListBox1.List(ListBox1.ListIndex, 25)
T26 = ListBox1.List(ListBox1.ListIndex, 26)
T27 = ListBox1.List(ListBox1.ListIndex, 27)
T28 = ListBox1.List(ListBox1.ListIndex, 28)
T29 = ListBox1.List(ListBox1.ListIndex, 29)
End Sub

Anzeige
;

Forumthreads zu verwandten Themen

Anzeige
Anzeige
Anzeige
Anzeige
Entdecke relevante Threads

Schau dir verwandte Threads basierend auf dem aktuellen Thema an

Alle relevanten Threads mit Inhaltsvorschau entdecken
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Entdecke mehr
Finde genau, was du suchst

Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden

Suche nach den besten Antworten
Unsere beliebtesten Threads

Entdecke unsere meistgeklickten Beiträge in der Google Suche

Top 100 Threads jetzt ansehen
Anzeige