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
| Sub test()
Dim Dico As Object, C As Range, Mois As Integer, Plage As Range, Plage1 As Range
ligne = 1
Set Dico = CreateObject("Scripting.Dictionary")
With Sheets("Feuil1")
Mois = Application.Match(.[G2], .[Q:Q], 0)
For Each C In .Range(.[A2], .Cells(.Rows.Count, 1).End(xlUp))
If C.Offset(, 2) >= DateSerial(2012, Mois, 1) Then
.Cells(C.Row, 14) = Application.Max(DateSerial(2012, Mois, 1), C.Offset(, 1))
End If
If C.Offset(, 2) <= DateSerial(2012, Mois + 1, 0) Then
.Cells(C.Row, 15) = Application.Min(DateSerial(2012, Mois + 1, 0), C.Offset(, 2))
End If
If Not Dico.exists(C.Value) Then
Dico.Add C.Value, C.Value
End If
Next C
Set Plage = .Range(.[A1], Cells(.Rows.Count, 1).End(xlUp)).Resize(, 15)
For Each Item In Dico.items
.AutoFilterMode = False
Set Plage1 = Plage
Plage1.AutoFilter 1, Item
Plage1.AutoFilter 5, .[H2]
Plage1.AutoFilter 14, ">=" & Format(DateSerial(2012, Mois, 1), "mm/dd/yyyy")
Plage1.AutoFilter 15, "<=" & Format(DateSerial(2012, Mois + 1, 0), "mm/dd/yyyy")
If Application.Subtotal(103, .[A:A]) > 1 Then
ligne = ligne + 1
.Cells(ligne, 11) = Item
.Cells(ligne, 12) = Application.Subtotal(109, .[C:C]) - Application.Subtotal(109, .[B:B])
End If
Next Item
.AutoFilterMode = False
.[N:O].ClearContents
End With
End Sub |
Partager