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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Sub test(occurs As String)
Dim c As Range, Ctr As Double, x As Range
Dim Ligne As Long, LigneDeb As Long, LigneCred As Long
Dim Min As Date, Dico As Object
With Sheets(occurs)
Ligne = 2
Set Dico = CreateObject("Scripting.Dictionary")
For Each c In Range(.[E4], .Cells(Rows.Count, 5).End(xlUp))
If Not Dico.exists(DateSerial(Year(c.Value), Month(c.Value), 1)) Then
Dico.Add DateSerial(Year(c.Value), Month(c.Value), 1), _
DateSerial(Year(c.Value), Month(c.Value), 1)
End If
Next c
[AH:AH].ClearContents
i = 0
For Each Item In Dico.items
i = i + 1
.Cells(i, "AH") = Item
Next Item
[AH:AH].Sort Range("AH1"), xlAscending, Header:=xlNo
For Each x In Range(.[AH1], .Cells(Rows.Count, "AH").End(xlUp))
Ctr = 0
Ligne = Ligne + 2
.Cells(Ligne, 26) = DateSerial(Year(x.Value), Month(x.Value), 1)
.Cells(Ligne, 26).NumberFormat = "mmm-yyyy"
LigneDeb = Ligne
LigneCred = Ligne
For Each c In Range(.[E4], .Cells(Rows.Count, 5).End(xlUp))
If DateSerial(Year(c.Value), Month(c.Value), 1) = .Cells(Ligne, 26) Then
If c.Offset(, 2) > 0 Then
.Cells(LigneCred, "AA") = .Cells(c.Row, 3)
.Cells(LigneCred, "AB") = .Cells(c.Row, 5)
.Cells(LigneCred, "AC") = .Cells(c.Row, 8)
.Cells(LigneCred, "AD") = .Cells(c.Row, 7)
Ctr = Ctr + .Cells(c.Row, 7)
LigneCred = LigneCred + 1
Else
.Cells(LigneDeb, "V") = .Cells(c.Row, 3)
.Cells(LigneDeb, "W") = .Cells(c.Row, 5)
.Cells(LigneDeb, "X") = .Cells(c.Row, 8)
.Cells(LigneDeb, "Y") = .Cells(c.Row, 7)
Ctr = Ctr + .Cells(c.Row, 7)
LigneDeb = LigneDeb + 1
End If
End If
Next c
.Cells(Ligne + 1, 26) = Ctr
.Cells(Ligne + 1, 26).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
Ligne = Application.Max(LigneCred, LigneDeb)
Next x
[AH:AH].ClearContents
End With
End Sub |