VBA Insert top border for a row when cell content is different from the last row. Sub Macro1() ' Dim strText As String Dim strText2 As String i = 2 For i = 2 To 4000 strText = Cells(i, 5).Value strText2 = Cells(i + 1, 5).Value If (strText <> strText2) Then Rows(i + 1).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone With Selection.Borders(xlEdgeTop) ...