Using SUM() in VBA

前端 未结 4 596
离开以前
离开以前 2021-01-11 11:46

If I have a set of cells in a worksheet that I want to add up, I can use the formula:

=SUM(Sheet1!A1:A10)

To do this in a sub, I would use:

4条回答
  •  情歌与酒
    2021-01-11 12:42

    I believe the issue with the worksheetfunction.sum is that it needs arguments to evaluate not string. WorksheetFunction.Sum("Sheet1!A1:A3") fails as well. However, this succeeds

    Application.WorksheetFunction.Sum(Sheet1.Range("A1"), Sheet2.Range("A1"))
    

    The Ranges could be whatever you like.

提交回复
热议问题