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)
                .LineStyle = xlContinuous
                .ThemeColor = 9
                .TintAndShade = 0
                .Weight = xlThin
            End With
            Selection.Borders(xlEdgeBottom).LineStyle = xlNone
            Selection.Borders(xlEdgeRight).LineStyle = xlNone
            Selection.Borders(xlInsideVertical).LineStyle = xlNone
            Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        
        End If
        
        
    Next i
    
End Sub


留言

這個網誌中的熱門文章