我想在总行的顶部添加边框线,并在底部添加边框线
例如:我有从第2行到第3行和第3-4列的数据,然后我添加了一个合计行,它将第5行中的第2-3行相加。
我想在第5行的顶部和底部添加一条边框线,并且仅向上添加到第4列。
我是否可以使用变量LastRow +2(注意,我在最后一行数据和总行之间有一个空行)和LastColumn一些how in Range("A5:D5").Select,因为它每次都是可变的?
我当前的代码:
Range("A5:D5").Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With发布于 2012-03-16 21:19:13
我认为NexttRow的事情仍然是一个好主意,代码也可以简化,这会将row2中的sum和格式化到数据的底部,无论它在哪里:
NR = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("C" & NR, "D" & NR).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
With Range("A" & NR, "D" & NR)
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThin
End With发布于 2012-03-16 12:03:05
您并不真正需要LastRow或LastCol变量。只需像这样引用范围的最后一行:
With Range("A5:D5")
With .Rows(.Rows.Count)
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End With您可以将其概括为一个子例程,您可以将一个范围传递给该子例程。
https://stackoverflow.com/questions/9731587
复制相似问题