VBA对可变长度的列求和 [英] VBA Summing a Column of Variable Length

查看:71
本文介绍了VBA对可变长度的列求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个VBA问题(我最近很着急)如标题所示,我试图求和一列可以是可变长度的列,然后将该和保留在单元格F3中,但是我遇到了应用程序或对象定义的错误.

Another VBA question (I'm on fire lately) As the title says, I am trying to sum a column that can can be of a variable length and then stick that sum in cell F3, but I am running into a an "application or object defined error.

这是我的代码:

Dim last As Range, sum As Variant

    ActiveSheet.Range("M8").Select
    Set last = Selection.End(xlDown)
    With Worksheets("Data")
        sum = WorksheetFunction.sum(.Range("M8:M" & last))
    End With

    Range("F:3") = sum

推荐答案

With Worksheets("Data")
    .Range("F3").Value = Application.Sum(.Range(.Range("M8"), .Range("M8").End(xlDown))
End With

这篇关于VBA对可变长度的列求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆