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 26 27 28 29 30
| Sub report()
Dim coltotal As Integer
ColFin = Sheets("Feuil1").Range("IV1").End(xlToLeft).Column
LigFin = Sheets("Feuil1").Range("A65536").End(xlUp).Row
Sheets("Feuil1").Range(Cells(1, 1).Address, Cells(LigFin, ColFin - 1).Address).Copy Destination:=Sheets("Feuil3").Range("A1")
colfin1 = Sheets("Feuil2").Range("IV1").End(xlToLeft).Column
Sheets("Feuil2").Range(Cells(1, 3).Address, Cells(1, colfin1).Address).Copy Destination:=Sheets("Feuil3").Cells(1, ColFin)
For n = 2 To Sheets("Feuil2").Range("A65536").End(xlUp).Row
For m = 2 To Sheets("Feuil3").Range("A65536").End(xlUp).Row
If Sheets("Feuil2").Range("A" & n) & Sheets("Feuil2").Range("B" & n) = Sheets("Feuil3").Range("A" & m) & Sheets("Feuil3").Range("B" & m) Then
Sheets("Feuil2").Range(Cells(n, 3).Address, Cells(n, colfin1).Address).Copy Destination:=Sheets("Feuil3").Cells(m, ColFin)
trouve = True
End If
Next m
If trouve = False Then
finf3 = Sheets("Feuil1").Range("A65536").End(xlUp).Row + 1
Sheets("Feuil2").Range(Cells(n, 1).Address, Cells(n, 2).Address).Copy Destination:=Sheets("Feuil3").Cells(finf3, 1)
Sheets("Feuil2").Range(Cells(n, 3).Address, Cells(n, colfin1).Address).Copy Destination:=Sheets("Feuil3").Cells(finf3, ColFin)
End If
trouve = False
Next n
coltotal = Sheets("Feuil3").Range("IV1").End(xlToLeft).Column
For n = 2 To Sheets("Feuil3").Cells(65536, coltotal).End(xlUp).Row
Cells(n, coltotal).Formula = "=SUM(C" & n & ":" & lettre(coltotal - 1) & n & ")"
Next n
End Sub
Function lettre(nb As Integer)
lettre = Left(Cells(1, nb).Address(0, 0), Len(Cells(1, nb).Address(0, 0)) - 1)
End Function |
Partager