Option Explicit
Sub Générer()
GénérerFeuille Feuil2, Feuil1.[A1].Value, Feuil1.[A2].Value
GénérerFeuille Feuil3, Feuil1.[B1].Value, Feuil1.[B2].Value
GénérerFeuille Feuil4, Feuil1.[C1].Value, Feuil1.[C2].Value, Feuil1.[D17].Value
End Sub
Sub GénérerFeuille(ByVal WshCibl As Worksheet, ByVal Code1 As String, ByVal Code2 As String, Optional ByVal MatCont)
Dim CelADéb As Range, NbLig As Long, ZMsg As String
Set CelADéb = WshCibl.[A1000000].End(xlUp).Offset(1)
NbLig = WshCibl.[D1000000].End(xlUp).Row + 1 - CelADéb.Row
If NbLig > 0 Then
With CelADéb.Resize(NbLig)
.Formula = "=""" & Code1 & Format(Date, "ddmmyyyy") _
& Code2 & """&TEXT(ROW()-" & CelADéb.Row - 1 & ",""00"")"
.Value = .Value
If Not IsMissing(MatCont) Then .Offset(, 1).Value = MatCont
End With
If NbLig > 1 Then ZMsg = NbLig & " lignes ont été numérotées" Else ZMsg = "Une ligne à été numérotée"
MsgBox ZMsg & " sur """ & WshCibl.Name & """.", vbInformation, "Générer"
Else
MsgBox "Aucune ligne n'a été numérotée sur """ & WshCibl.Name & """.", vbExclamation, "Générer"
End If
End Sub