English 中文(简体)
VBA的苏米波段
原标题:Sum range-loop in VBA

我想把一栏到T栏的浏览量汇总起来,并在第五栏中显示结果。

目前,我的法典是:

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

I get the error message: "Run-time error 1004 : Method Range of object Global failed"

我做了什么错误?

问题回答

The initial macro with Nathan_Sav s correction made the code work. However, used a different approach to optimize running time. Here it is:

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




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签