Sub exportmec()
Dim a(), b(), x(), y(), ws As Worksheet
premierjour = DateSerial(Year(Date), Month(Date) - 1, 1)
dernierjour = DateSerial(Year(Date), Month(Date) + 12, 1) - 1
haut = premierjour - DateSerial(Year(Date), 1, 1) + 2 + 365
bas = Date - DateSerial(Year(Date), 1, 1) + 1 + 365
x = Array("BDD MEC GROUPE", "BDD CA GROUPE", "BDD MEC INDIV", "BDD CA INDIV")
y = Array(2, 3, 4, 5)
With Worksheets("pivotgroup").PivotTables("Tableau croisé dynamique1")
.PivotFields("DATE").ClearLabelFilters
.PivotFields("DATE").PivotFilters.Add Type:=xlDateBetween, Value1:="" & premierjour, Value2:="" & dernierjour
Nombre = .DataBodyRange.Rows.Count - 1
adr = .DataBodyRange.Columns(1).Resize(Nombre, 5).Cells.Address(0, 0)
.PivotFields("DATE").ClearLabelFilters
End With
a = Feuil17.Range("A6" & Mid(adr, 3)).Value 'tableau avec dates et valeurs
For k = LBound(x) To UBound(x)
Set ws = Sheets(x(k))
b = ws.Range(ws.Cells(haut, 1), ws.Cells(bas, 1)).Value 'date
ReDim c(1 To UBound(b, 1), 1 To 1) 'pour valeur
For i = 2 To UBound(a, 1)
For l = 1 To UBound(b, 1)
If b(l, 1) = a(i, 1) Then
If a(i, y(k)) <> "" Then
c(l, 1) = a(i, y(k)) 'valeur
End If
End If
Next l
Next i
' f = ws.Rows(1).Find(what:=premierjour, LookIn:=xlFormulas).Column
ws.Cells(haut, haut).Resize(UBound(c, 1), 1) = c
Next k
End Sub