Sub Transfert()
Dim ncol%, Sh As Worksheet, Sh1 As Worksheet, Sh2 As Worksheet, ShDest As Worksheet, critere As Byte, n&, i&, j&, rc&
ncol = 20 'nombre de colonnes
Set Sh = ActiveSheet
Set Sh1 = Sheets("Situation ") 'pourquoi un espace ???
Set Sh2 = Sheets("Entrepôt")
If Sh.Name = Sh1.Name Then Set ShDest = Sh2: critere = 0
If Sh.Name = Sh2.Name Then Set ShDest = Sh1: critere = 1
If ShDest Is Nothing Then Exit Sub
If Sh.FilterMode Then Sh.ShowAllData 'si la feuille est filtrée
If ShDest.FilterMode Then ShDest.ShowAllData 'si la feuille est filtrée
With Sh.Range("B5:B" & Sh.Range("E" & Sh.Rows.Count).End(xlUp).Row).Resize(, ncol)
If .Row < 5 Then Exit Sub 'si le tableau est vide
n = Application.CountIf(.Columns(2), critere)
If n = 0 Then Exit Sub
Application.ScreenUpdating = False
.Sort .Columns(2), IIf(critere = 0, xlDescending, xlAscending), Header:=xlNo 'tri pour regrouper et accélérer
.Borders.LineStyle = xlNone 'efface toute bordure
i = Application.Match(critere, .Columns(2), 0)
j = ShDest.Range("E" & ShDest.Rows.Count).End(xlUp).Row + 1
rc = .Rows.Count 'mémorise
.Rows(i).Resize(n).Cut ShDest.Cells(j, 2) 'couper-coller
If n < rc Then
.BorderAround Weight:=xlMedium 'pourtour
.Borders(xlEdgeTop).LineStyle = xlNone
End If
End With
With ShDest.Cells(j, 2).Resize(n, ncol)
.BorderAround Weight:=xlMedium 'pourtour
.Borders(xlEdgeTop).LineStyle = xlNone
End With
ShDest.Activate 'facultatif
End Sub