Voici ma macro : Dim date1 As Variant
date1 = Names('Dat1')
Dim date2 As Variant
date2 = Names('Dat2')
Sheets('Contrôle ER').Select ' remise a zero feuille du résultat
Cells.Select
Selection.ClearContents
Range('A1').Select
ActiveCell.FormulaR1C1 = ' Compte '
Range('B1').Select
ActiveCell.FormulaR1C1 = ' Solde Initial '
Range('C1').Select
ActiveCell.FormulaR1C1 = ' Mouvement '
Range('D1').Select
ActiveCell.FormulaR1C1 = ' Solde Final '
Range('E1').Select
ActiveCell.FormulaR1C1 = ' Ecart'
Sheets('Contrôle ER').Select
Sheets('ER').Select
la = 2 'début de tableau
While Cells(la, 'A') > ''
la = la + 1
Wend
la = la - 1 'rectification la = derniere ligne
Lfin = 2 'initialisation
For Ltab = 2 To la 'boucle principale
Sheets('ER').Select
Cells(Ltab, 'A').Select
Selection.Copy
cpte = Cells(Ltab, 'A')
Sheets('Contrôle ER').Select
Cells(Lfin, 'A').Select
ActiveSheet.Paste
Sheets('ER').Select
Cells(Ltab, 'C').Select
Application.CutCopyMode = False
Selection.Copy
Sheets('Contrôle ER').Select
Cells(Lfin, 'B').Select
ActiveSheet.Paste
Ltab = Ltab + 1 '
Sheets('ER').Select
While Cells(Ltab, 'A') = cpte
If Left(Cells(Ltab, 'B'), 4) <> 'SOLD' Then Cells(Ltab, 'C').Copy: Sheets('Contrôle ER').Select: Cells(Lfin, 'C').Select: Selection.PasteSpecial Paste:=xlAll, Operation:=xlAdd, SkipBlanks:=False, Transpose:=False: Sheets('ER').Select: Ltab = Ltab + 1
' variante si toutes les lignes qui ne sont pas des mouvements commencent par 'solde '
'et si aucun mouvement ne commence par solde
' If Left(Cells(Ltab, 'B'), 4) = 'Mouv' Then Cells(Ltab, 'C').Copy: Sheets('Contrôle ER').Select: Cells(Lfin, 'C').Select: Selection.PasteSpecial Paste:=xlAll, Operation:=xlAdd, SkipBlanks:=False, Transpose:=False: Sheets('ER').Select: Ltab = Ltab + 1
If Sheets('ER').Cells(Ltab, 'B') = 'SOLDE IRIS' Then Ltab = Ltab + 1
If Sheets('ER').Cells(Ltab, 'B') = 'date1' Then Ltab = Ltab + 1
If Sheets('ER').Cells(Ltab, 'B') = 'date2' Then Cells(Ltab, 'C').Copy: Sheets('Contrôle ER').Select: Cells(Lfin, 'D').Select: Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Wend
Cells(Lfin, 'E').Select
' Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = '=RC[-3]+RC[-2]-RC[-1]'
Lfin = Lfin + 1
Next