AW: ListBox / doppelte Auflistung / Addieren - Teil 2
27.10.2010 15:50:20
CitizenX
Hallo Mike,
..so sollte es gehen:
'**************************************************
'* H. Ziplies *
'* 07.10.04; 09.06.06 *
'* erstellt von Hajo.Ziplies@web.de *
'* http://Hajo-Excel.de/
*
'**************************************************
Private Sub UserForm_Activate()
Dim LoLetzte As Long
Dim LoI As Long
Dim LoJ As Long
With Worksheets("Test")
'----------------------------------------------------------------------------------------------- _
_
Dim Bereich As Range _
Dim lngRowLast As Long
Dim i As Long
Set Bereich = Range("E:E") _
With Bereich _
lngRowLast = .Find("Bezahlt !", after:=.Cells(.Rows.Count, .Columns.Count), LookIn:= _
xlValues, searchdirection:=xlPrevious, searchorder:=xlByRows).Row '*
End With _
_
'----------------------------------------------------------------------------------------------- _
' letzte belegte Zeile mit gleichem Wochentag
i = lngRowLast + 1
Do While .Cells(lngRowLast + 1, 1) = .Cells(i, 1)
i = i + 1
Loop
'wenn nur ein Wochentag vorhanden dann Letzte = Erste ; sonst Letzte
LoLetzte = IIf(i = lngRowLast + 1, lngRowLast + 1, i - 1)
'Schleife über die gleichen Wochentage ab Bezahlt!
For LoI = lngRowLast + 1 To LoLetzte
If Application.WorksheetFunction.CountIf(.Range(.Cells(LoI, 5), .Cells(lngRowLast, _
5)), Cells(LoI, 5)) = 1 Then
'Summe der Artikel
LoJ = Application.WorksheetFunction.SumIf(.Range(.Cells(lngRowLast, 5), .Cells( _
LoLetzte, 5)), _
.Cells(LoI, 5), .Range(.Cells( _
lngRowLast, 4), .Cells(LoLetzte, 4)))
ListBox1.AddItem LoJ
' Spalte 2 Name
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(LoI, 5)
' Spalte 3 Einzelpreis Spalte G
ListBox1.List(ListBox1.ListCount - 1, 2) = Format(.Cells(LoI, 7), "#,##.00 ")
' Spalte 4 Gesamtprei, Einzelpreis * Anzahl
ListBox1.List(ListBox1.ListCount - 1, 3) = Format(.Cells(LoI, 7) * LoJ, "#,##. _
00 ")
End If
Next LoI
End With
End Sub
Grüße
Steffen