2017-03-01 34 views

回答

0

這裏有點像一個想法。它不是完整的解決方案,但你可以從它開始,建立你自己的,通過消除幻數等...

Option Explicit 

Public Sub SortingBorders() 

    Dim rngMyRng As Range 
    Dim rngCell  As Range 

    Set rngMyRng = Range("A1:A20") 
    Call RemoveAllBorders(rngMyRng) 

    For Each rngCell In rngMyRng 
     If rngCell <> rngCell.Offset(1, 0) Then 
      Range(rngCell.Offset(1, 0), rngCell.Offset(1, 5)).Borders(xlEdgeTop).LineStyle = xlContinuous 
     End If 
    Next rngCell 

End Sub 

Public Sub RemoveAllBorders(rngMyRng As Range) 

    With rngMyRng 
     .Borders(xlDiagonalDown).LineStyle = xlNone 
     .Borders(xlDiagonalUp).LineStyle = xlNone 
     .Borders(xlEdgeLeft).LineStyle = xlNone 
     .Borders(xlEdgeTop).LineStyle = xlNone 
     .Borders(xlEdgeBottom).LineStyle = xlNone 
     .Borders(xlEdgeRight).LineStyle = xlNone 
     .Borders(xlInsideVertical).LineStyle = xlNone 
     .Borders(xlInsideHorizontal).LineStyle = xlNone 
    End With 

End Sub 

這是你會得到什麼: enter image description here

解決方案善有善報第1列,並且只有在條件rngCell <> rngCell.Offset(1, 0)爲真時才放置邊框。

+0

謝謝你的想法。這不是解決方案,但這個想法是正確的。它工作正常。謝謝 –