添加列的总行数D - M
问题描述:
我一直在使用这种语法为D列添加一行总数 - 但现在我需要为D-M添加总行数,而不是只多次写这些代码并更改列名是否有一个快速可重用的函数,可以将总行添加到列D - M的底部?添加列的总行数D - M
With ActiveSheet
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("D1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
End With
Range("D" & lastrow +1).FormulaR1C1 = "=SUM(R[-" & lastrow & "]C:R[-1]C)"
答
这与突出显示范围,按Ctrl +右箭头
同样的效果range("D" & lastrow + 1 & ":M" & lastrow + 1).FillRight
优秀,得到了我的答案,也学到了新的VBA函数。谢谢! –