Re,
Une proposition VBA à étudier avec un résultat sous forme TCD (tableau croisé dynamique).
ALT F8 et exécuter la procédure main.
Cdlt.
Public Sub Main()
Dim pt As PivotTable
Dim lo As ListObject
Dim tbl, arr()
Dim r As Range, rngGroup As Range
Dim endDate As Long, startDate As Long
Dim I As Long, J As Long, k As Long
tbl = Range("Input").Value
Set lo = Range("Output").ListObject
Set pt = Worksheets("Output").PivotTables(1)
With lo
If Not .DataBodyRange Is Nothing Then .DataBodyRange.Delete
Set r = .InsertRowRange.Cells(1)
End With
For I = LBound(tbl) To UBound(tbl)
If IsDate(tbl(I, 4)) And VBA.Year(tbl(I, 4)) < VBA.Year(Date) Then
startDate = CLng(DateSerial(VBA.Year(Date), 1, 1))
Else
startDate = CLng(tbl(I, 4))
End If
If IsDate(tbl(I, 5)) And VBA.Year(tbl(I, 5)) > VBA.Year(Date) Then
endDate = CLng(DateSerial(VBA.Year(Date), 12, 31))
ElseIf IsDate(tbl(I, 5)) And VBA.Year(tbl(I, 5)) = VBA.Year(Date) Then
endDate = CLng(tbl(I, 5))
Else
endDate = CLng(VBA.DateAdd("d", -1, Date))
End If
For J = startDate To endDate
ReDim Preserve arr(2, k + 1)
arr(0, k) = tbl(I, 1) & ", " & tbl(I, 2)
arr(1, k) = J
k = k + 1
Next J
Next
If k > 0 Then r.Resize(k, 2).Value = Application.Transpose(arr)
With pt
.PivotCache.Refresh
Set rngGroup = .PivotFields("Dates").DataRange
rngGroup.Cells(1).Group Periods:=Array(False, False, False, False, True, False, False)
End With
End Sub