VBA
Insert top border for a row when cell content is different from the last row.
Sub Macro1()'Dim strText As StringDim strText2 As Stringi = 2For i = 2 To 4000strText = Cells(i, 5).ValuestrText2 = Cells(i + 1, 5).ValueIf (strText <> strText2) ThenRows(i + 1).SelectSelection.Borders(xlDiagonalDown).LineStyle = xlNoneSelection.Borders(xlDiagonalUp).LineStyle = xlNoneSelection.Borders(xlEdgeLeft).LineStyle = xlNoneWith Selection.Borders(xlEdgeTop).LineStyle = xlContinuous.ThemeColor = 9.TintAndShade = 0.Weight = xlThinEnd WithSelection.Borders(xlEdgeBottom).LineStyle = xlNoneSelection.Borders(xlEdgeRight).LineStyle = xlNoneSelection.Borders(xlInsideVertical).LineStyle = xlNoneSelection.Borders(xlInsideHorizontal).LineStyle = xlNoneEnd IfNext iEnd Sub
留言
張貼留言