AW: Variable Summenformel
17.03.2008 23:27:10
Erich
Hi Peter,
so könnte ich mir eine solche Funktion vorstellen:
| G | H | I |
28 | 7.708.190,00 | 7.708.190,00 | 7.708.190,00 |
29 | | | |
36 | | | |
37 | 407.370,00 | 407.370,00 | 407.370,00 |
Formeln der Tabelle |
Zelle | Formel | G28 | =SUMME(E8:E27) | H28 | =SumSpezN(1;5) | I28 | =SumSpezB("A";"E") | G37 | =SUMME(E32:E36) | H37 | =SumSpezN(1;5) | I37 | =SumSpezB("A";"E") |
|
Und so sind die Funktionen definiert (in ein normales Modul):
Option Explicit
Function SumSpezN(intSpA As Integer, intSpS As Integer)
Dim lngZ As Long, lngV As Long
lngZ = Application.Caller.Row
lngV = Cells(lngZ, intSpA).End(xlUp).Row
SumSpezN = WorksheetFunction.Sum(Range(Cells(lngV, intSpS), Cells(lngZ - 1, intSpS)))
End Function
Function SumSpezB(strA As String, strS As String)
Dim lngZ As Long, lngV As Long
lngZ = Application.Caller.Row
lngV = Cells(lngZ, strA).End(xlUp).Row
SumSpezB = WorksheetFunction.Sum(Range(Cells(lngV, strS), Cells(lngZ - 1, strS)))
End Function
Noch eine Bemerkung zu "A28 wäre ja in jedem Fall activecell.address".
Das stimmt nicht so ganz. Eine beutzerdefinierte Fkt. kann auch berechnet werden,
während irgend eine andere Zelle die aktive ist.
Wichtig ist, aus welcher Zelle heraus die Fkt. aufgerufen wird (wo also die Formel steht).
Das bekommt man mit dem Application.Caller.
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort