Option Explicit
Sub TestMitFunktion()
Dim rngTyp As Excel.Range
Dim rngWert As Excel.Range
Dim rngSumme As Excel.Range
Dim Rng As Excel.Range
If Len(Cells(2, 1)) = 0 Then Exit Sub
'ab Zeile 2 bis Ende
Set rngTyp = Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp))
Set rngWert = rngTyp.Offset(, 1)
Set rngSumme = rngTyp.Offset(, 2)
For Each Rng In rngSumme
Rng.Value = WorksheetFunction.SumIf(rngTyp, Rng.Offset(, -2), rngWert)
Next Rng
End Sub
Sub TestMitFormel()
Dim TypAddi As String
Dim WertAddi As String
Dim SumAddi As String
If Len(Cells(2, 1)) = 0 Then Exit Sub
'ab Zeile 2 bis Ende
TypAddi = Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp)).Address
WertAddi = Replace(TypAddi, "A", "B")
SumAddi = Replace(TypAddi, "A", "C")
Cells(2, 3).Formula = "=SUMIF(" & TypAddi & ",A2," & WertAddi & ")"
Range(SumAddi).FillDown
End Sub
|