Option Explicit
Sub CalculMiseEnForme()
Dim xrg As Range, xcell As Range
Application.ScreenUpdating = False
With Sheets("Rec-Dep")
'tri complet
Set xrg = .Cells(.Rows.Count, "a").End(xlUp)
Set xrg = .Range(.Cells(3, "a"), .Cells(xrg.Row, "f"))
xrg.Sort .Cells(1, "a"), Header:=xlNo
'recherche parmi les dates du lendemain ou vide
Set xrg = .Cells(.Rows.Count, "a").End(xlUp)
Set xrg = .Range(.Cells(3, "a"), xrg)
For Each xcell In xrg
If Len(xcell) = 0 Then Exit For
If xcell.Value2 > CLng(Date) Then Exit For
Next xcell
'tri selon libellé puis date des échéances (non échues)
Set xrg = .Range(xcell, .Cells(.Range("a" & Rows.Count).End(xlUp).Row, "f"))
xrg.Sort key1:=xcell(1, 3), key2:=xcell, Header:=xlNo
'On fait de la place pour les nouvelles écritures
xcell.Resize(15, 6).Insert shift:=xlShiftDown, copyorigin:=xlFormatFromLeftOrAbove
'Application de la formule en colonne F
Set xrg = .Cells(.Rows.Count, "a").End(xlUp)
Set xrg = .Range(.Cells(3, "f"), .Cells(xrg.Row, "f"))
xrg.FormulaR1C1 = _
"=IF(RC[-5]>TODAY(),"""",IF(AND(RC[-2]=0,RC[-1]=0),"""",R[-1]C-RC[-2]+RC[-1]))"
' on masque la calculette
.Shapes.Range(Array("00_Bouton")).Visible = False
'on se place sur la première cellule de saisie
.Activate
xcell.Offset(-15).Select
End With
Application.ScreenUpdating = True
End Sub