1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| Function SumBefore(PivotDate As Date)
Dim Formula As String
Dim lngFirstday As Long
Dim lngPivot As Long
lngPivot = PivotDate * 1
lngFirstday = (PivotDate - Day(PivotDate) + 1) * 1
Formula = "=SUMIFS(Tableau1[Valeur],Tableau1[Date],"">=|FirstDay|"",Tableau1[Date],""<|Pivot|"")"
Formula = Replace(Formula, "|FirstDay|", lngFirstday, , , vbTextCompare)
Formula = Replace(Formula, "|Pivot|", lngPivot, , , vbTextCompare)
SumBefore = Evaluate(Formula)
End Function
Function SumAfter(PivotDate As Date)
Dim Formula As String
Dim lngFirstday As Long
Dim lngPivot As Long
lngPivot = PivotDate * 1
lngFirstday = DateSerial(Year(PivotDate), Month(PivotDate) + 1, 1) * 1
Formula = "=SUMIFS(Tableau1[Valeur],Tableau1[Date],"">=|Pivot|"",Tableau1[Date],""<|FirstDay|"")"
Formula = Replace(Formula, "|FirstDay|", lngFirstday, , , vbTextCompare)
Formula = Replace(Formula, "|Pivot|", lngPivot, , , vbTextCompare)
SumAfter = Evaluate(Formula)
End Function |
Partager