Simplification par des variables

Bonjour,

J'ai créé un formatage conditionnel pour tracer une bordure qui sépare les cellules de la colonne B lorsque celles-ci sont différentes (voir fichier joint, un onglet avec mon fichier de départ, un onglet avec le fichier de sortie désiré).

Le code fonctionne bien mais je n'arrive pas à le simplifier avec des variables. Il faut que le code fonctionne jusqu'à la ligne 40000.

Merci de votre aide.

Sub Test_border()

If Range("B2").Value <> Range("B3").Value Then Rows("2:2").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B3").Value <> Range("B4").Value Then Rows("3:3").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B4").Value <> Range("B5").Value Then Rows("4:4").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B5").Value <> Range("B6").Value Then Rows("5:5").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B6").Value <> Range("B7").Value Then Rows("6:6").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B7").Value <> Range("B8").Value Then Rows("7:7").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B8").Value <> Range("B9").Value Then Rows("8:8").Borders(xlEdgeBottom).Weight = xlMedium

If Range("B9").Value <> Range("B10").Value Then Rows("9:9").Borders(xlEdgeBottom).Weight = xlMedium

End Sub

4example.xlsx (15.15 Ko)

Bonjour,

à tester,

Sub Test_border()
Dim LastRw As Long, i As Long
LastRw = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To LastRw
    If Range("B" & i).Value <> Range("B" & i + 1).Value Then Rows(i).Borders(xlEdgeBottom).Weight = xlMedium
Next i
End Sub

Bonjour,

Merci beaucoup, ça fonctionne parfaitement !

Sophia.

Rechercher des sujets similaires à "simplification variables"