die ListBox1 wird mittels Array gefüllt, wobei mit eine If Anweisung ein Datumfilter erfolgt.
Wie bekomme ich nun diese gefilterten Daten in eine andere Tabelle?
'Auswahl anzeigen Datum
<pre>Private Sub CommandButton17_Click()
Dim i As Long, maxlen As Long, Li As Long, ii As Long, LC As Long
Dim str As String, str2 As String, arr As Variant
Dim Startdatum As Date, EndDatum As Date
Dim wsName As String
Dim Kat As String
wsName = Me.ComboBox3.Value
Worksheets(wsName).Activate
'geändert auf CDate(UserForm4.tbx_Startdatum)
'in einer Textbox steht Text der wird mit
'CDate in ein Datum gewandelt
Startdatum = CDate(Me.TextBox2)
EndDatum = CDate(Me.TextBox3)
Kat = Me.TextBox1
maxlen = 35
With ListBox1
.Clear
.ColumnCount = 10
.ColumnWidths = "3cm;6cm;3cm;3cm;3cm;3cm;0cm;0cm;0cm;0cm" 'Spalte 6 Bestand wird ausgeblendet
'hier geändert von i=9 auf i=10 (ohne die Kopfzeilen)
'Spaltenbeschriftung über Label
For i = 11 To Cells(Rows.Count, "B").End(xlUp).Row '11=ohne Saldozeile
Li = i - 9
str = Cells(i, 3)
If CDate(Cells(i, 2)) >= Startdatum And CDate(Cells(i, 2)) <= EndDatum _
Then
.AddItem
LC = .ListCount - 1
.List(LC, 0) = Cells(i, 2) 'SpalteB in Spalte1
.List(LC, 1) = Cells(i, 3) 'Original-Text speichern SpalteC
.List(LC, 2) = Cells(i, 4) 'SpalteD in dritte Spalte3
.List(LC, 3) = Cells(i, 5) 'SpalteD in dritte Spalte3
.List(LC, 4) = Format(Cells(i, 6), "#,##0.00 ") 'SpalteE in dritte Spalte4
.List(LC, 5) = Format(Cells(i, 7), "#,##0.00 ") 'SpalteF in dritte Spalte5
.List(LC, 6) = Format(Cells(i, 8), "#,##0.00 ") 'SpalteH in dritte Spalte5
.List(LC, 8) = Li 'Zeilen-Nr speichern
.List(LC, 9) = Cells(i, 3) 'Original-Text speichern
str = Cells(i, 3)
If i > 9 Then
If str = "" Then str = " "
arr = Split(str, " ")
str2 = arr(0)
For ii = 1 To UBound(arr)
If Len(str2 & arr(ii)) + 1 <= maxlen Then
str2 = str2 + " " + arr(ii)
Else
.AddItem
LC = .ListCount - 1
'.List(LC, 0) = Cells(i, 2) 'SpalteA in Spalte1
.List(LC, 1) = Cells(i, 3) 'Original-Text speichern
'.List(LC, 2) = Cells(i, 4) 'SpalteD in dritte Spalte3
'.List(LC, 3) = Format(Cells(i, 5), "#,###.00 ") 'SpalteE in dritte Spalte4
'.List(LC, 4) = Format(Cells(i, 6), "#,###.00 ") 'SpalteF in dritte Spalte5
'.List(LC, 5) = Format(Cells(i, 7), "#,###.00 ") 'SpalteG in dritte Spalte6
.List(LC, 8) = Li 'Zeilen-Nr speichern
.List(LC, 9) = Cells(i, 3) 'Original-Text speichern
str2 = arr(ii)
End If
.List(.ListCount - 1, 1) = str2
Next ii
End If
End If
Next i
End With
'ab hier Summen der gefilterten Zeilen aus Listbox
Dim intSum1 As Currency
Dim intSum2 As Currency
'Summe Spalte3=SpalteE=Einnahmen
With ListBox1
For i = 0 To .ListCount - 1
If .List(i, 4) > "" Then
intSum1 = intSum1 + .List(i, 4)
End If
Next
End With
Label6 = intSum1
Label6 = Format(Label6, "#,##0.00 ")
'Summe Spalte4=SpalteF=Ausgaben
With ListBox1
For i = 0 To .ListCount - 1
If .List(i, 5) > "" Then
intSum2 = intSum2 + .List(i, 5)
End If
Next
End With
Label7 = intSum2
Label7 = Format(Label7, "#,##0.00 ")
'Summe Einnahmen ./. Ausgaben in Label8
Label8 = Label6 - Label7
Label8 = Format(Label8, "#,##0.00 ")
'Anfang Anfangbestand und Endbestand in jeweils ausgewähltem Bereich
With ListBox1
If ListBox1.ListCount > 0 Then
Label18 = (.List(0, 6))
Label18 = Format(Label18, "#,##0.00 ")
Label19 = (.List(0, 4))
Label19 = Format(Label19, "#,##0.00 ")
Label20 = (.List(0, 5))
Label20 = Format(Label20, "#,##0.00 ")
Label21 = CDbl(Label18) - CDbl(Label19) + CDbl(Label20)
Label21 = Format(Label21, "#,##0.00 ")
Label22 = CDbl(Label21) + CDbl(Label6) - CDbl(Label7)
Label22 = Format(Label22, "#,##0.00 ")
End If
End With
'Ende Anfangbestand und Endbestand in jeweils ausgewähltem Bereich
If ListBox1.ListCount > 0 Then
CommandButton3.Enabled = True
End If
End Sub</pre>
ES geht nur um die Werte der ListBox nicht um die Summenwerte aus den Label.
Besten Dank für eure Hilfe.
Gruss
Peter