Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1804to1808
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

Hilfe beim Array()

Hilfe beim Array()
20.01.2021 08:34:09
CMFA
Hallo Liebes Forum,
um es gleich vorne weg zu nehmen, ich habe mich noch nie so richtig mit Array beschäftig. Nun stehe ich aber vor dem Problem das ich in eine Listbox, mit AddItem, mehr als 10 Spalten bringen muss. Die Daten werden aus einer anderen Tabelle eingesammelt. Bisher habe ich es so gelöst:
With Workbooks("RWG_Daten.xlsx").Sheets("RWG")
lc = 12 'Zähler für ListCount um die entsprechende Monatzzahl abzuziehen
For a = 1 To 12
If Len(a) = 2 Then
strtext = "*." & a & "." & Year(Now)
Else
strtext = "*.0" & a & "." & Year(Now)
End If
Set c = .Range("AT2:AT" & .Rows.Count).Find(strtext, LookIn:=xlValues, lookat:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False)
Information.ListBox5.AddItem Format(Month(Now) & " " & a, "MMMM") & " " & Year(Now)
If Not c Is Nothing Then
strFirst = c.Address
Do
Information.ListBox5.AddItem .Cells(c.Row, 43).Value
If InStr(.Cells(c.Row, 44).Value, ";")  0 Then
xstr = Split(.Cells(c.Row, 44).Value, ";")
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 1) = xstr(0)
Else
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 1) = .Cells(c.Row, 44). _
Value
End If
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 2) = .Cells(c.Row, 45). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 3) = .Cells(c.Row, 46). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 4) = .Cells(c.Row, 1).Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 5) = .Cells(c.Row, 47). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 6) = .Cells(c.Row, 2).Value
Set c = .Range("AT2:AT" & .Rows.Count).FindNext(c)
Loop While Not c Is Nothing And c.Address  strFirst
End If
If ydnv - 1 >= 1 Then
With Workbooks("RWG_Daten.xlsx").Sheets("DNV")
Set cc = .Range("D2:D" & .Rows.Count).Find(strtext, LookIn:=xlValues, lookat:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False)
If Not cc Is Nothing Then
strFirst = cc.Address
Do
Information.ListBox5.AddItem .Cells(cc.Row, 1).Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 1) = .Cells(cc.Row, 2). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 2) = .Cells(cc.Row, 3). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 3) = .Cells(cc.Row, 4). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 4) = .Cells(cc.Row, 6). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 5) = .Cells(cc.Row, 5). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 6) = .Cells(cc.Row, 7). _
Value
Information.ListBox5.List(Information.ListBox5.ListCount - 1, 7) = .Cells(cc.Row, 8). _
Value
Set cc = .Range("D2:D" & .Rows.Count).FindNext(cc)
Loop While Not cc Is Nothing And cc.Address  strFirst
End If
End With
End If
If c Is Nothing Then
Information.ListBox5.RemoveItem (Information.ListBox5.ListCount - 1)
lc = lc - 1
End If
Next
End With

Wie bekomme ich das nun in einem Array hin das ich auch weitere Informationen in die Listbox holen kann.
VG CMFA

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Hilfe beim Array()
20.01.2021 08:38:36
CMFA
sorry mein Explorer ist abgestürtz, nur ein Beitrag ist aktuell
AW: Hilfe beim Array()
20.01.2021 08:47:03
Hajo_Zi
gut Du hast durch Deinen Beitrag den Beitrag aus der Liste der offenen gelöscht.
Antworte jetzt nicht hier und Stelle auf offen, damit sieht man den ersten Beitrag nicht.
Gruß Hajo
AW: Hilfe beim Array()
20.01.2021 08:53:11
CMFA
ok
AW: Hilfe beim Array()
20.01.2021 14:31:48
Daniel
Hi
Am einfachsten ohne Array
Lege ein zusätzliches Tabellenblatt an.
Kopiert da die benötigten Daten in der richtigen Reihenfolge rein bzw lösche die nicht benötigten Zeilen und Spalten
Überträge dann die Liste als ganzes in die Listbox.
Das geht am einfachsten über
ListBox1.List = Sheets(...).Range("A1").CurrentRegion.Value
Das geht auch mit vielen Spalten.
Kleiner Tip: im Sortieren ist Excel sehr schnell.
Bevor man viele einzelne Zeile oder Spalten Löscht, Bann es sinnvoll sein, zuerst so zu sortieren, dass alles was gelöscht werden soll ans Ende kommt, damit es in einem Schritt gelöscht werden kann.
Dabei sollte man sich auch vor temporär eingefügten Hilfszeilen oder -spalten nicht scheuen, die können hilfreich sein, um den Vorgang zu beschleunigen.
Statt dem Zuweisen von .Value an .List kannst du auch die Listbox direkt mit dem bereinigten Zellbereich verknüpfen, indem du die Adresse des Zellbereichs in die RowSource/ListFillrange-Eigenschaft schreibst. (Mit Angabe destabellenblatts)
Listbox1.RowSource = "'TabelleX'!" & Sheets("TabelleX").Range("A1").CurrentRegion.Address

Vorteil ist, dass du dann deine Listbox mit Dpaltenüberschriften versehen könntest, was insbesondere bei Tabellen mit vielen Spalten hilfreich ist.
Gruß Daniel
Anzeige
AW: Hilfe beim Array()
20.01.2021 14:20:50
ChrisL
Hi
Die Zwischentitel finde ich nicht so toll (hat m.E. nichts in einer Listenauswahl zu suchen).
ydnv konnte ich nicht einordnen, weshalb ich mich auf den ersten Teil konzentriert habe. Wenn du die Anzahl Spalten erweiterst (im Moment nur 3), dann hier anpassen:
ReDim Preserve MyArray(2, lngZaehler)
Beachte, dass Array im Standard ab 0 zählen, daher 2 = 3 Spalten
Dim MyArray() As Variant
Dim rngSuchbereich As Range, c As Range
Dim intMonat As Integer
Dim strText As String, strFirst As String
Dim lngZaehler As Long
With Workbooks("RWG_Daten.xlsx").Sheets("RWG")
Set rngSuchbereich = .Range("AT2:AT" & .Cells(Rows.Count, 1).End(xlUp).Row)
For intMonat = 1 To 12
strText = Format(intMonat, "00") & "." & Year(Now)
If Not rngSuchbereich.Find(strText, LookIn:=xlValues, lookat:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) Is Nothing Then
ReDim Preserve MyArray(2, lngZaehler)
MyArray(0, lngZaehler) = Format(DateSerial(Year(Now), intMonat, 1), "MMMM YYYY")
lngZaehler = lngZaehler + 1
Set c = rngSuchbereich.Find(strText, LookIn:=xlValues, lookat:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
strFirst = c.Address
Do
ReDim Preserve MyArray(2, lngZaehler)
MyArray(0, lngZaehler) = .Cells(c.Row, 43)
MyArray(1, lngZaehler) = Split(.Cells(c.Row, 44), ";")(0)
MyArray(2, lngZaehler) = .Cells(c.Row, 45)
' hier erweitern
lngZaehler = lngZaehler + 1
Set c = rngSuchbereich.FindNext(c)
Loop While c.Address  strFirst
End If
Next intMonat
Information.ListBox5.List = Application.Transpose(MyArray)
End With
cu
Chris
Anzeige
AW: Hilfe beim Array()
21.01.2021 05:08:50
CMFA
danke Chris, das hat mir geholfen.
Die Zwischentitel sind leider für einige Mitarbeiter zwingend, damit sie die Übersicht nicht verlieren. Mir ist da keine andere Lösung eingefallen
VG CMfa
AW: Hilfe beim Array()
21.01.2021 08:08:15
ChrisL
Hi
Danke für die Rückmeldung.
Üblicherweise macht man eine separate Monatsauswahl und lädt dann nur den betreffenden Monat.
Wenn es sich um eine Monatsübergreifende Mehrfachauswahl handelt, dann richtig sortieren und bei Bedarf in einer zusätzlichen Spalte die Monate wiederholen.
Weitere, ausgeklügeltere Varianten sind denkbar z.B. wie Excel-Optionen, Menüband anpassen (Combobox mit unterschiedlichen Gruppierungen, hinzufügen/entfernen).
cu
Chris
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige