Option Compare Text 'la casse est ignorée
Dim F As Worksheet, n&, X!, Y! 'mémorise les variables
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$J$3" Then Exit Sub
Dim w As Worksheet
Set F = Sheets("Etiquettes")
F.DrawingObjects.Delete 'RAZ
F.ResetAllPageBreaks
n = 0: X = 0: Y = 0
If Target = "Toutes" Then
For Each w In Worksheets
If IsNumeric(w.Name) Then
Etiquettes w.Name
End If
Next w
ElseIf Target <> "" Then
Etiquettes CStr(Target)
End If
End Sub
Sub Etiquettes(souche$)
Dim s1 As Shape, s2 As Shape, T, i&, j&
Set s1 = Shapes("ZT_1"): Set s2 = Shapes("ZT_2")
Application.ScreenUpdating = False
Set T = Sheets(souche).ListObjects(1).Range
For i = 2 To T.Rows.Count Step 2
If T(i, 7) = "couple" Then
n = n + 1
s1.Copy
F.Paste
F.Shapes(n).Left = X
F.Shapes(n).Top = Y
If n Mod 2 Then
X = F.Shapes(n).Width
Else
X = 0
Y = Y + F.Shapes(n).Height
End If
If n Mod 16 = 0 Then F.HPageBreaks.Add F.Shapes(n).BottomRightCell.EntireRow 'sauts de pages
MAJ T, i
Else
For j = i To i + 1
n = n + 1
s2.Copy
F.Paste
F.Shapes(n).Left = X
F.Shapes(n).Top = Y
If n Mod 2 Then
X = F.Shapes(n).Width
Else
X = 0
Y = Y + F.Shapes(n).Height
End If
If n Mod 16 = 0 Then F.HPageBreaks.Add F.Shapes(n).BottomRightCell.EntireRow 'sauts de pages
MAJ T, j
Next j
End If
Next i
Application.Goto F.[A1], True 'cadrage
End Sub
Sub MAJ(T, i&)
Dim txt$
txt = F.Shapes(n).TextFrame.Characters.Text
txt = Replace(txt, "NOM PRENOM", T(-3, 3))
txt = Replace(txt, "1960", T(0, 3))
If T(i, 7) = "couple" Then
txt = Replace(txt, "01 et 02", Format(T(i, 1), "00") & " et " & Format(T(i + 1, 1), "00"))
txt = Replace(txt, "2025", T(i, 5))
txt = Replace(txt, "2024", T(i + 1, 5))
txt = Replace(txt, "011", Format(T(i, 4), "000"))
txt = Replace(txt, "015", Format(T(i + 1, 4), "000"))
txt = Replace(txt, "Perruche 1", T(i, 3))
txt = Replace(txt, "Perruche 2", T(i + 1, 3))
txt = Replace(txt, "40 E", T(i + 1, 7) & " E")
Else
txt = Replace(txt, "32a", Format(T(i, 1), "00"))
txt = Replace(txt, "2024", T(i, 5))
txt = Replace(txt, "040", Format(T(i, 4), "000"))
If T(i, 6) = "M" Then txt = Replace(txt, "FEMELLE", "MALE") Else txt = Replace(txt, "Femelle", "FEMELLE")
txt = Replace(txt, "Perruche", T(i, 3))
txt = Replace(txt, "40 E", T(i, 7) & " E")
End If
F.Shapes(n).TextFrame.Characters.Text = txt
End Sub