Réponse acceptée !
Salut
J'ai essayé un truc a toi de voir si ca marche chez toi et surtout si c'est ce que tu cherches.
Sur la feuille 1 j'ai les trades et un CommandButton1 et la feuille 2 affiche l'agrégation.
Voila le code :
Dim IndexHeure As Integer
Dim Ligne As Integer
Dim LigneAffichage As Integer
Dim CoursMontant As Boolean
Dim CoursDescendant As Boolean
Dim CoursMonotone As Boolean
Private Sub AnalyseCours()
Do
If Worksheets(1).Cells(Ligne, 2) <> Worksheets(1).Cells(Ligne - 1, 2) Then
If Worksheets(1).Cells(Ligne, 2) > Worksheets(1).Cells(Ligne - 1, 2) Then
CoursMontant = True
CoursMonotone = False
If CoursMontant = CoursDescendant Then
If CoursMonotone = False Then
Agregation
IndexHeure = Ligne
End If
End If
CoursDescendant = False
Else
CoursDescendant = True
CoursMonotone = False
If CoursMontant = CoursDescendant Then
If CoursMonotone = False Then
Agregation
IndexHeure = Ligne
End If
End If
CoursMontant = False
End If
Else
CoursMonotone = True
End If
AnalyseHeure
Ligne = Ligne + 1
Loop Until Worksheets(1).Cells(Ligne, 1) = ""
Agregation
End Sub
Private Sub AnalyseHeure()
If (Worksheets(1).Cells(IndexHeure, 1) * 24 * 60 * 60) - (Worksheets(1).Cells(Ligne, 1) * 24 * 60 * 60) > 0.1 Then
Agregation
IndexHeure = Ligne
CoursMontant = False
CoursDescendant = False
CoursMonotone = True
End If
End Sub
Private Sub CommandButton1_Click()
CoursMontant = False
CoursDescendant = False
CoursMonotone = True
IndexHeure = 1
Ligne = 2
LigneAffichage = 1
AnalyseCours
End Sub
Private Sub Agregation()
For i = IndexHeure To Ligne - 1
Volume = Volume + Worksheets(1).Cells(i, 3)
Cours = Cours + (Worksheets(1).Cells(i, 2) * Worksheets(1).Cells(i, 3))
Next i
Worksheets(2).Cells(LigneAffichage, 1) = Worksheets(1).Cells(IndexHeure, 1)
Worksheets(2).Cells(LigneAffichage, 2) = Format(Cours / Volume, "########0.00")
Worksheets(2).Cells(LigneAffichage, 3) = Volume
LigneAffichage = LigneAffichage + 1
End Sub
j'ai les fichiers excel que je peux t'envoyer par mail si tu veux.
Dorian