Private Sub Worksheet_Change(ByVal Target As Range)
Dim deb As Date, fin As Date, dest As Range, d As Object, dat As Variant, resu(), n&, flag As Boolean, i&
deb = [A3] 'à adapter
fin = [A5] 'à adapter
Set dest = [C7] 'à adapter
'---mémorisation des jours fériés pour accélérer---
Set d = CreateObject("Scripting.Dictionary")
For Each dat In [Feries].Value: d(dat) = "": Next
'---tableau des résultats---
ReDim resu(1 To 2 * IIf(fin < deb, 0, fin - deb) + 3, 1 To 3)
n = -1
For dat = deb To fin
If Not flag And Weekday(dat, 2) < 6 And Not d.exists(dat) Then
flag = True
n = n + 2
resu(n, 1) = "PERIODE " & 1 + (n - 1) / 2
resu(n, 2) = "DATE DE DEPART"
resu(n, 3) = dat
resu(n + 1, 2) = "DATE DE RETOUR"
End If
If flag And (Weekday(dat, 2) > 5 Or d.exists(dat)) Then flag = False: resu(n + 1, 3) = dat - 1
Next
If n > -1 Then If resu(n + 1, 3) = "" Then resu(n + 1, 3) = fin
resu(n + 2, 1) = "IMPUTATION BUDGETAIRE"
resu(n + 2, 3) = Application.VLookup("IMPUTATION BUDGETAIRE", dest.EntireColumn.Resize(, 3), 3, 0)
'---restitution---
Application.ScreenUpdating = False
Application.EnableEvents = False 'désactive les évènements
dest(2).Resize(Rows.Count - dest.Row, 3).Delete xlUp 'RAZ
dest(2).Resize(n + 2, 3) = resu
'---fusion des cellules---
If n > 1 Then
For i = 1 To n Step 2
dest(i + 1).Resize(2).Merge
dest(i + 1).VerticalAlignment = xlCenter
Next
ElseIf n = 1 Then
dest(2, 2).Resize(2).Cut dest(2)
dest(2).Resize(, 2).Merge
dest(3).Resize(, 2).Merge
End If
dest(n + 3).Resize(, 2).Merge 'IMPUTATION BUDGETAIRE
'---bordures---
dest(2).Resize(n + 2, 3).Borders.Weight = xlThin 'bordures
Application.EnableEvents = True 'réactive les évènements
End Sub