对多维数组的特定元素范围求和

时间:2022-02-16 21:32:45

How can I sum a specific range of elements of a multi-dimension array without using a For... Nextstatement?

如何在不使用For ... Nextstatement的情况下对多维数组的特定元素范围求和?

I know how to do it with a 1-dimension array. For example, the next code:

我知道如何用一维数组做到这一点。例如,下一个代码:

Dim GRMORT(1 to 864) As Double
Dim PSUM as Double
PSUM = Application.Sum(Application.Index(GRMORT, 1, Evaluate("ROW(100:200")")))

return the sum of the 100th to 200th elements. However, if I use a 2-dimension array:

返回第100个到第200个元素的总和。但是,如果我使用二维数组:

Dim GRMORT(1 to 864, 1 to 24) As Double

the function doesn't work. I thought it had to be with the second argument of the Index function, so I tried change it to 2, 3, ... But that wasn't the solution.

该功能不起作用。我认为必须使用Index函数的第二个参数,所以我尝试将其更改为2,3,......但这不是解决方案。

How can I change the Indexfunction to get the sum of the 100th to 200th elements of the fourth column (or any other column)?

如何更改Index函数以获得第四列(或任何其他列)的第100个到第200个元素的总和?

1 个解决方案

#1


3  

Just supply the column argument:

只需提供列参数:

Dim GRMORT(1 To 864, 1 To 5) As Double
Dim PSUM As Double
PSUM = Application.Sum(Application.Index(GRMORT, Evaluate("ROW(100:200)"), 4))

#1


3  

Just supply the column argument:

只需提供列参数:

Dim GRMORT(1 To 864, 1 To 5) As Double
Dim PSUM As Double
PSUM = Application.Sum(Application.Index(GRMORT, Evaluate("ROW(100:200)"), 4))