Sub Encadrement()
Dim ws As Worksheet
Dim rng As Range
Dim b As Borders
'--- Feuille cible
Set ws = ThisWorkbook.Worksheets(ActiveSheet.Name)
'--- Dernière ligne utilisée
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'--- Dernière colonne utilisée
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
'--- Plage bornée
Set rng = ws.Range(ws.Cells(2, 9), ws.Cells(lastRow, lastCol)) ' 9 = colonne I
'--- Test visuel
'rng.Select
'--- Bordures de la plage
Set b = rng.Borders
'--- Étape 1 : supprimer toutes les bordures
b(xlDiagonalDown).LineStyle = xlNone
b(xlDiagonalUp).LineStyle = xlNone
b(xlEdgeLeft).LineStyle = xlNone
b(xlEdgeTop).LineStyle = xlNone
b(xlEdgeBottom).LineStyle = xlNone
b(xlEdgeRight).LineStyle = xlNone
b(xlInsideVertical).LineStyle = xlNone
b(xlInsideHorizontal).LineStyle = xlNone
'--- Étape 1 : Recréer des bordures autour de chaque cellule
With b
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
''--- Étape 2 : ajouter uniquement celles que tu veux
' With b(xlEdgeLeft)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
' End With
'
' With b(xlEdgeTop)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
' End With
'
' With b(xlEdgeBottom)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
' End With
'
' With b(xlEdgeRight)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
' End With
End Sub