Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1584to1588
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
Array to ListBox
12.10.2017 08:56:23
Antonio
Hallo Gemeinde,
mein Problem is für mich etwas schwierig zu lösen.
Ich habe im Archiv das gefunden:
Private Sub cmdSearch_Click()
Dim c As Range
Dim rngBereich As Range
Dim lngAnzahl As Long
Dim strFirst As String
With Sheets("Daten")
Set rngBereich = .Columns("A:H")
Set c = rngBereich.Find(txtSearch, LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
strFirst = c.Address
Do
ListBox1.AddItem .Cells(c.Row, 1)
lngAnzahl = ListBox1.ListCount
ListBox1.List(lngAnzahl - 1, 1) = .Cells(c.Row, 2)
ListBox1.List(lngAnzahl - 1, 2) = .Cells(c.Row, 3)
ListBox1.List(lngAnzahl - 1, 3) = .Cells(c.Row, 4)
ListBox1.List(lngAnzahl - 1, 4) = .Cells(c.Row, 5)
ListBox1.List(lngAnzahl - 1, 5) = .Cells(c.Row, 6)
ListBox1.List(lngAnzahl - 1, 6) = .Cells(c.Row, 7)
ListBox1.List(lngAnzahl - 1, 7) = .Cells(c.Row, 8)
Set c = rngBereich.FindNext(c)
Loop While Not c Is Nothing And c.Address  strFirst
End If
End With
End Sub
umgeschrieben so das es für mich passt:
With ListBox6 'ListBox6 füllen
.Clear
.ForeColor = RGB(0, 0, 255)
.ColumnCount = 11
.ColumnWidths = "0;0;350;0;0;0;0;0;0;0;0;0"
End With
Dim c As Range
Dim rngBereich As Range
Dim lngAnzahl As Long
Dim strFirst As String
With Sheets("Lampen")
Set rngBereich = .Columns("E:E")
Set c = rngBereich.Find(TextBox100.text, LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
strFirst = c.Address
Do
ListBox6.AddItem .Cells(c.Row, 1)
lngAnzahl = ListBox6.ListCount
ListBox6.List(lngAnzahl - 1, 1) = .Cells(c.Row, 2)
ListBox6.List(lngAnzahl - 1, 2) = .Cells(c.Row, 3)
ListBox6.List(lngAnzahl - 1, 3) = .Cells(c.Row, 4)
ListBox6.List(lngAnzahl - 1, 4) = .Cells(c.Row, 5)
ListBox6.List(lngAnzahl - 1, 5) = .Cells(c.Row, 6)
ListBox6.List(lngAnzahl - 1, 6) = .Cells(c.Row, 7)
ListBox6.List(lngAnzahl - 1, 7) = .Cells(c.Row, 8)
ListBox6.List(lngAnzahl - 1, 8) = .Cells(c.Row, 9)
ListBox6.List(lngAnzahl - 1, 9) = .Cells(c.Row, 10)
' ListBox6.List(lngAnzahl - 1, 10) = .Cells(c.Row, 11)
' ListBox6.List(lngAnzahl - 1, 11) = .Cells(c.Row, 12)
Set c = rngBereich.FindNext(c)
Loop While Not c Is Nothing And c.Address strFirst
End If
End With
aber mit dieser Methode komme ich nicht über die 10 Spalten,
habe versucht ein Array zu bilden:
Dim c As Range
Dim rngBereich As Range
Dim arrFill As Variant
With Sheets("Lampen")
Set rngBereich = .Columns("E:E")
Set c = rngBereich.Find(TextBox100.text, LookIn:=xlValues, lookat:=xlPart)
arrFill = Sheets("Lampen").Range("Tabelle4")
ListBox6.List() = arrFill
End With
ohne Erfolgt, es wird mir immer die komplete Spalte(E) wieder gegeben und nicht nach den TextBox100.text.
Kann mich bitte jemandem ein Tipp geben?
Danke in Voraus
Antonio

16
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Array to ListBox
12.10.2017 09:15:32
Daniel
Hi
Sortiere die Liste nach Spalte E, so dass alle Zeilen, die in die Listbox sollen, direkt untereinander stehen.
Ermittle dann die Zeilennummer des ersten Treffers (Worksheetfunction.Match) und die Anzahl der Treffer (Worksheetfunction.CountIf) und Weise dann den ganzen Block der Listbox zu:
Listbox1.List = Cells(erste Zeile, 1).Resize(Anzahl Zeilen, Anzahl Spalten).Value
Gruß Daniel
AW: Array to ListBox
12.10.2017 09:40:02
Antonio
Danke Daniel für dein feedback, werde versuchen, dann melde mich
Antonio
AW: Array to ListBox
12.10.2017 10:05:40
Antonio
Sorry Daniel ich schaffe es nicht, habe versucht mit diesem Test:
Sub Test_Count()
Dim myRange As Range
Dim x As Integer
Set myRange = Worksheets("Lampen").Range("E:E")
x = Application.WorksheetFunction.CountIf(myRange)
MsgBox x
End Sub
leider MsgBox x=0
....und komme nicht weiter.
was mache ich falsch?
Antonio
Anzeige
AW: Array to ListBox
12.10.2017 10:19:03
Daniel
Hi
naja, in deinem CountIf fehlt doch noch der Suchbegriff.
das CountIf entspricht dem ZählenWenn in Excel.
x = Application.WorksheetFunction.CountIf(myRange, textbox100.Text)
gleiches gilt natürlich für das Application.Match, welches der Funktion Vergleich entspricht.
ich würde das countif auch zuerst ausführen, dann kannst du gleich prüfen, ob der Suchbegriff auch in der Liste vorhanden ist:
dim Zeile as Long
dim Anzahl as Long
dim myRange as range
Set myRange = Worksheets("Lampen").Range("E:E")
Anzahl = Application.WorksheetFunction.CountIf(myRange, Textbox100.Text)
if Anzahl > 0 then
Zeile = Application.Worksheetfunction.Match(Textbox100.Text, myRange, 0)
Listbox1.List = Sheets("Lampen").Cells(Zeile, 1).Resize(Anzahl, 12).Value
else
Listbox1.Clear
end if
vergiss nicht die Sortierung der Tabelle nach Spalte E
Gruß Daniel
Anzeige
AW: Array to ListBox
12.10.2017 10:25:23
Nepumuk
Hallo Antonio,
ich würde das so machen:
Private Sub CommandButton1_Click()
    Dim c As Range
    Dim ialngIndex As Long
    Dim strFirst As String
    Dim avntValues() As Variant
    
    With ListBox6
        Call .Clear
        .ForeColor = RGB(0, 0, 255)
        .ColumnCount = 11
        .ColumnWidths = "0;0;350;0;0;0;0;0;0;0;0"
    End With
    
    With Worksheets("Lampen")
        Set c = .Columns("E:E").Find(TextBox100.Text, _
            LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
        If Not c Is Nothing Then
            strFirst = c.Address
            Do
                Redim Preserve avntValues(10, ialngIndex)
                avntValues(0, ialngIndex) = .Cells(c.Row, 2)
                avntValues(1, ialngIndex) = .Cells(c.Row, 3)
                avntValues(2, ialngIndex) = .Cells(c.Row, 4)
                avntValues(3, ialngIndex) = .Cells(c.Row, 5)
                avntValues(4, ialngIndex) = .Cells(c.Row, 6)
                avntValues(5, ialngIndex) = .Cells(c.Row, 7)
                avntValues(6, ialngIndex) = .Cells(c.Row, 8)
                avntValues(7, ialngIndex) = .Cells(c.Row, 9)
                avntValues(8, ialngIndex) = .Cells(c.Row, 10)
                avntValues(9, ialngIndex) = .Cells(c.Row, 11)
                avntValues(10, ialngIndex) = .Cells(c.Row, 12)
                ialngIndex = ialngIndex + 1
                Set c = .Columns("E:E").FindNext(c)
            Loop Until c.Address = strFirst
            Set c = Nothing
            ListBox6.Column = avntValues
        Else
            Call MsgBox("Nix gefunden", vbExclamation, "Hinweis")
        End If
    End With
End Sub

Gruß
Nepumuk
Anzeige
AW: Array to ListBox
12.10.2017 10:52:16
Antonio
vielen Dank zunächst,
@Daniel "Sortieren" war schon, weil es kommen immer nue Einträge dazu und es wird gleich sortiert.
Danke dir so much (:-)
@Nepumuk habe es ausprobiert und die richtige Spaltennummerierng geändert, Funzt schon aber vermisse die leztzten 3 Spalten da sie in die Textboxen nicht erscheinen, vielleicht liegt daran das es kein Array ist
...ODER... (;-)
AW: Array to ListBox
12.10.2017 10:55:41
Antonio
Daniel sorry, bei dir vermisse ich auch die letzten 3 Spalten, und weiß nicht wie ich das änderen kann, alles andere passt
Antonio
AW: Array to ListBox
12.10.2017 11:04:22
Daniel
Hi
der zweite Parameter in der Resize-Funktion gibt die Anzahl der Spalten an, die aus der Exceltabelle in die Listbox übernommen werden.
Außerdem musst du in Listboxeigenschaft "ColumnCount" die Anzahl der Spalten richtig eingeben und bei "ColumnWidth" auch für alle Spalten eine Spaltenbreite angeben.
Gruß Daniel
Anzeige
AW: Array to ListBox
12.10.2017 11:56:03
Antonio
Witziger Weise werden mir in den TextBoxen 8 davon gefüllt 3 bleiben leer.
Resize-Funktion zweite Parameter = 11
Listboxeigenschaft "ColumnCount" =11 - "ColumnWidth" was minimal gegeben
Antonio
AW: Array to ListBox
12.10.2017 12:23:47
Daniel
TextBoxen?
davon war noch nie die Rede.
Hier gings darum, eine Listbox zu befüllen
Gruß Daniel
AW: Array to ListBox
12.10.2017 10:57:04
Nepumuk
Hallo Antonio,
du hast in diese Zeile:
.ColumnWidths = "0;0;350;0;0;0;0;0;0;0;0"
alle Spalten bis auf eine ausgeblendet.
Gruß
Nepumuk
AW: Array to ListBox
12.10.2017 11:58:12
Antonio
Habe die .ColumnWidths geändert,
eventuell könnte meine Änderung der Spalten Nummerierung?
Do
' ReDim Preserve avntValues(10, ialngIndex)
' avntValues(0, ialngIndex) = .Cells(c.Row, 1)
' avntValues(1, ialngIndex) = .Cells(c.Row, 2)
' avntValues(2, ialngIndex) = .Cells(c.Row, 3)
' avntValues(3, ialngIndex) = .Cells(c.Row, 4)
' avntValues(4, ialngIndex) = .Cells(c.Row, 5)
' avntValues(5, ialngIndex) = .Cells(c.Row, 6)
' avntValues(6, ialngIndex) = .Cells(c.Row, 7)
' avntValues(7, ialngIndex) = .Cells(c.Row, 8)
' avntValues(8, ialngIndex) = .Cells(c.Row, 9)
' avntValues(9, ialngIndex) = .Cells(c.Row, 10)
' avntValues(10, ialngIndex) = .Cells(c.Row, 11)
' ialngIndex = ialngIndex + 1
Antonio
Anzeige
AW: Array to ListBox
12.10.2017 12:00:54
Nepumuk
Hallo Antonio,
sorry, aber ich kann dir nicht folgen.
Gruß
Nepumuk
AW: Array to ListBox
12.10.2017 12:11:25
Antonio
Deine Liste (achte bitte auf (c.Row,....)
Redim Preserve avntValues(10, ialngIndex)
avntValues(0, ialngIndex) = .Cells(c.Row, 2)
avntValues(1, ialngIndex) = .Cells(c.Row, 3)
avntValues(2, ialngIndex) = .Cells(c.Row, 4)
avntValues(3, ialngIndex) = .Cells(c.Row, 5)
avntValues(4, ialngIndex) = .Cells(c.Row, 6)
avntValues(5, ialngIndex) = .Cells(c.Row, 7)
avntValues(6, ialngIndex) = .Cells(c.Row, 8)
avntValues(7, ialngIndex) = .Cells(c.Row, 9)
avntValues(8, ialngIndex) = .Cells(c.Row, 10)
avntValues(9, ialngIndex) = .Cells(c.Row, 11)
avntValues(10, ialngIndex) = .Cells(c.Row, 12)
ialngIndex = ialngIndex + 1
meine geänderte Auflistung
' ReDim Preserve avntValues(10, ialngIndex)
' avntValues(0, ialngIndex) = .Cells(c.Row, 1)
' avntValues(1, ialngIndex) = .Cells(c.Row, 2)
' avntValues(2, ialngIndex) = .Cells(c.Row, 3)
' avntValues(3, ialngIndex) = .Cells(c.Row, 4)
' avntValues(4, ialngIndex) = .Cells(c.Row, 5)
' avntValues(5, ialngIndex) = .Cells(c.Row, 6)
' avntValues(6, ialngIndex) = .Cells(c.Row, 7)
' avntValues(7, ialngIndex) = .Cells(c.Row, 8)
' avntValues(8, ialngIndex) = .Cells(c.Row, 9)
' avntValues(9, ialngIndex) = .Cells(c.Row, 10)
' avntValues(10, ialngIndex) = .Cells(c.Row, 11)
' ialngIndex = ialngIndex + 1
Anzeige
AW: Array to ListBox
12.10.2017 12:14:46
Nepumuk
Äääääääääääää ja ok und nun?
Sollte auf alle Fälle auch funktionieren.
Gruß
Nepumuk
AW: Sorry Daniel,Nepumuk
12.10.2017 12:20:43
Antonio
Hallo meine Retter,
mein Fehler...
da ich Voher kein Array hatte, hatte nun 3 TextBoxen auskommentiert.
Alle TextBoxen wieder dabei.
Alle Code funzen
SORRY SORRY
Antonio
@Rückmeldung wäre schön

106 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige