excel最后一行自动求和

excel 在数据的最后一非空行的下一行 自动对上面的数据自动求和 行数随机产生的不固定 怎么写代码?

假如是A列吧
在其中插入一个模块将下面的代码复制
Sub
qiuhe()
Application.CommandBars("Worksheet
menu
bar").Controls.Add(Type:=msoControlPopup,
before:=11).Caption
=
"计算"
Application.CommandBars("Worksheet
menu
bar").Controls("计算").Controls.Add(Type:=msoControlButton,
before:=1).Caption
=
"求和"
Application.CommandBars("Worksheet
menu
bar").Controls("计算").Controls("求和").OnAction
=
"total_cacu"
End
Sub
sub
total_cacu()
dim
i,total_rows
as
integer
dim
tota
as
double
tota=0
total_rows
=
Worksheets("sheet1").[a65536].End(xlUp).Row
for
i=1
to
total_rows
step
1
tota=tota+cells(i,1).value
next
i
cells(total_rows+1,1).value=tota
end
sub
试试看行不行.因为我不知道你具体的表格格式,所以可能看上去有点单调。
程序能在菜单栏增加一个菜单项“计算”-“求和”,只要你点一下“求和”就可以实现你想要的了。前一段代码由于显示宽度的原因分了两行,复制到编辑器中注意会出错。这个只是手动计算,如果想自动那要用到监视单元格。一时半会我写不出来了,我也初学。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网