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.PageSetup.FitToPagesWide = 1
F.PageSetup.FitToPagesTall = 1
Application.ScreenUpdating = False
If Target = "Toutes" Then
For Each w In Worksheets
If IsNumeric(w.Name) Then Etiquettes w.Name
Next w
ElseIf Target <> "" Then
Etiquettes CStr(Target)
End If
If F.DrawingObjects.Count Then
'F.PrintOut ' pour imprimer
F.PrintPreview 'pour voir l'aperçu
F.DrawingObjects.Delete
n = 0: X = 0: Y = 0
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")
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
Do
On Error Resume Next
s1.Copy
F.Paste
Loop While Err
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
MAJ T, i
If n Mod 16 = 0 Then
'F.PrintOut ' pour imprimer
F.PrintPreview 'pour voir l'aperçu
F.DrawingObjects.Delete
n = 0: X = 0: Y = 0
End If
Else
For j = i To i + 1
n = n + 1
Do
On Error Resume Next
s2.Copy
F.Paste
Loop While Err
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
MAJ T, j
If n Mod 16 = 0 Then
'F.PrintOut 'pour voir l'aperçu
F.PrintPreview 'aperçu
F.DrawingObjects.Delete
n = 0: X = 0: Y = 0
End If
Next j
End If
Next i
End Sub
Sub MAJ(T, i&)
Dim txt$, p%
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
With F.Shapes(n).TextFrame
.Characters.Text = txt
p = InStr(txt, vbLf & "M ")
If p Then .Characters(p + 1, 1).Font.Bold = True
p = InStr(txt, "F ")
If p Then .Characters(p, 1).Font.Bold = True
p = InStr(txt, "VENTE")
If p Then .Characters(p).Font.Bold = True
p = InStr(txt, "Prix")
If p Then .Characters(p).Font.Bold = True
End With
End Sub