Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim F As Worksheet, derligF&, derlig&, nlig&, i&, x$, ajout As Boolean, j&
Set F = Sheets("feuil1")
If TypeName(Sh) <> "Worksheet" Or Sh.Name = F.Name Then Exit Sub
If F.FilterMode Then F.ShowAllData 'si la feuille est filtrée
If Sh.FilterMode Then Sh.ShowAllData 'si la feuille est filtrée
derligF = F.Range("A" & F.Rows.Count).End(xlUp).Row
If derligF < 3 Then Sh.Rows("3:" & Sh.Rows.Count).Delete: Exit Sub
derlig = Sh.Range("A" & Sh.Rows.Count).End(xlUp).Row
nlig = derlig
Application.ScreenUpdating = False
For i = 3 To derligF
x = CStr(F.Cells(i, 1))
If x <> "" Then
ajout = True
For j = 3 To nlig
If CStr(Sh.Cells(j, 1)) = x Then
Sh.Rows(j).Cut Sh.Rows(derlig + 1)
Sh.Rows(j).Delete
nlig = nlig - 1
ajout = False
Exit For
End If
Next j
If ajout Then 'ajoute la ligne manquante
Sh.Rows(derlig).AutoFill Sh.Rows(derlig).Resize(2), xlFillFormats 'copie les formats
derlig = derlig + 1
Sh.Cells(derlig, 1) = x
End If
End If
Next i
Sh.Rows(derligF + 1).Resize(Sh.Rows.Count - derligF).Delete 'supprime les lignes excédentaires
End Sub