Sub TriProfDate()
Dim Prof, Dat As Date, A&, M&, Te(), Le&, Ts(), Ls&, C
Prof = [B1].Value
Dat = [B2].Value: M = Month(Dat): A = Year(Dat)
Te = Feuil1.ListObjects(1).DataBodyRange.Value
ReDim Ts(1 To UBound(Te, 1), 1 To UBound(Te, 2) - 1)
For Le = 1 To UBound(Te, 1)
Dat = Te(Le, 1)
If Month(Dat) = M And Year(Dat) = A And Te(Le, 2) = Prof Then
Ls = Ls + 1
Ts(Ls, 1) = Te(Le, 1)
For C = 3 To UBound(Te, 2): Ts(Ls, C - 1) = Te(Le, C): Next C
End If
Next Le
Me.[A8:F100].ClearContents
Me.[A8].Resize(Ls, UBound(Ts, 2)).Value = Ts
End Sub
Private Sub Worksheet_Calculate()
Dim Prof, Dat As Date, A&, M&, Te(), Le&, Ts(), Ls&, C
Prof = [B1].Value
Dat = [B2].Value: M = Month(Dat): A = Year(Dat)
Te = Feuil1.ListObjects(1).DataBodyRange.Value
Static Somme
If Range("MaSomme") <> Somme Then
Somme = Range("MaSomme")
ReDim Ts(1 To UBound(Te, 1), 1 To UBound(Te, 2) - 1)
For Le = 1 To UBound(Te, 1)
Dat = Te(Le, 1)
If Month(Dat) = M And Year(Dat) = A And Te(Le, 2) = Prof Then
Ls = Ls + 1
Ts(Ls, 1) = Te(Le, 1)
For C = 3 To UBound(Te, 2): Ts(Ls, C - 1) = Te(Le, C): Next C
End If
Next Le
Me.[A8:F100].ClearContents
Me.[A8].Resize(Ls, UBound(Ts, 2)).Value = Ts
End If
End Sub
If Me.[Somme] = Somme Then Exit Sub
Option Explicit
Dim Somme
Private Sub Worksheet_Activate()
TriProfDate
Somme = Me.[Somme]
End Sub
Private Sub Worksheet_Calculate()
If Me.[Somme] = Somme Then Exit Sub
TriProfDate
Somme = Me.[Somme]
End Sub
Private Sub Worksheet_Calculate()
Dim nom$, an%, mois As Byte, t, a(), i&, n&
nom = [B1]
an = Year(DateValue("1 " & [B2]))
mois = Month(DateValue("1 " & [B2]))
t = [Tableau1]
ReDim a(1 To UBound(t), 1 To 6)
For i = 1 To UBound(t)
If Year(t(i, 1)) = an And Month(t(i, 1)) = mois And t(i, 2) = nom Then
n = n + 1
a(n, 1) = t(i, 1): a(n, 2) = t(i, 3)
a(n, 3) = t(i, 4): a(n, 4) = t(i, 5)
a(n, 5) = t(i, 6): a(n, 6) = a(n, 5) - a(n, 4)
End If
Next i
'---restitution et mise en forme---
Application.ScreenUpdating = False
Application.EnableEvents = False
Range("A8:F" & Rows.Count).Delete xlUp 'RAZ
If n Then
[A8].Resize(n, 6) = a
[F1] = Application.Sum(Application.Index(a, , 6))
[A8].Resize(n, 6).Borders.Weight = xlThin
End If
Application.EnableEvents = True
End Sub