Re : Loop à rebour pour un nombre fixe de répétitions
J'en suis arrivé à faire ça:
Dim row_depart As String, nom_depart As String, nom_courant As String, Dates_Mfg As Date, Essence As String, Count_depart As Integer, Count As Integer, Grade As String, Dim_nom As String, Res As Integer, Mode As Integer
Sub QSL()
'row_depart = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
nom_depart = Cells(row_depart, 2)
For I = 28 To 1 Step -1
nom_courant = Cells(row_depart - 1, 2)
Dim Sum As Long
Sum = 0
row_depart = ActiveCell.SpecialCells(xlCellTypeLastCell).Row 'tes données démarrent à partir de la seconde ligne
Do While nom_courant = nom_depart
Sum = Sum + Cells(row_depart, 17).Value 'Montants B1
row_depart = row_depart - 1
nom_depart = Cells(row_depart - 1, 2)
Loop
Cells(row_depart - 1, 18).Value = Sum
Next I
MsgBox Sum
End Sub
Ça marche pas comme je voudrais, mais c'est un départ. La Msgbox à la fin servait à vérifier des valeurs, mais pour l'instant j'obtient zéro. De plus, j'ai fait un bouton pour la macro, je verrai pour l'automatisation plus tard.
Merci encore!