【问题标题】:Sum range-loop in VBAVBA中的求和范围循环
【发布时间】:2016-01-08 13:30:19
【问题描述】:

我想将 I 列到 T 列的行求和,并将结果显示在 V 列中。

目前,我的代码是:

Sub Sum_column_V()

Dim lastRow As Long, i As Integer, totalItoT As Double, sht As Worksheet

Set sht = ThisWorkbook.Worksheets("Summary")

lastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

For i = 1 To lastRow
    totalItoT = WorksheetFunction.Sum(Range("I" & i & "T" & i))
Next
    sht.Range("V" & i) = totalItoT

End Sub

我收到错误消息:“运行时错误'1004':对象'全局的方法'范围'失败”

我做错了什么?

【问题讨论】:

  • :丢失。 i1:t10
  • -.-。谢谢@Nathan_Sav

标签: vba for-loop sum


【解决方案1】:

带有 Nathan_Sav 更正的初始宏使代码工作。但是,使用了不同的方法来优化运行时间。这里是:

Sub Sum_column_V()
Sheets("Summary").Select

Dim j As Integer
j = 2

While Cells(j, 1) <> ""
Cells(j, 22) = Application.Sum(Range(Cells(j, 9), Cells(j, 20)))
j = j + 1
Wend


End Sub

【讨论】:

    猜你喜欢
    • 2015-08-03
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多