Est-ce que ceci répond correctement à ta demande?
Sub Macro1()
Dim plage As Range
der_lig = Range("b" & Rows.Count).End(xlUp).Row + 1
ncarton = Range("b5")
nblig = 1
lig_dep = 5
For i = 6 To der_lig
If (Cells(i, 1) <> ncarton And Cells(i, 1) <> "") Or Cells(i, 2) = "" Or i = der_lig Then
If nblig > 1 Then
Set plage = Range("a" & lig_dep, "f" & i - 1)
With plage
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
End With
With plage.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With plage.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With plage.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With plage.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With plage.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
plage.Borders(xlInsideHorizontal).LineStyle = xlNone
Set plage = Nothing
nblig = 1
End If
If Cells(i, 1) <> "" Then
lig_dep = i
ncarton = Cells(i, 1)
End If
Else
nblig = nblig + 1
End If
Next i
End Sub
J'ai testé chez moi et ça marche, mais je ne sais pas si ça marche comme tu voudrais.