![]() |
Applying Sum Function to 2nd Dimension of Array
How do you sum a particulate dimension in an array? That is I have
2-D Array. I want to sum the 2nd dimension. Normally if it were 1-D would go: ArraySum = Application.WorksheetFunction.Sum(Array) But if Array is a 2-D array, how do I qualify that I only want the 2n dimension summed -- Message posted from http://www.ExcelForum.com |
Applying Sum Function to 2nd Dimension of Array
I assume you mean a specifc column in the array.
ArraySum = Application.Sum(Application.Index(Array,0,3)) the above sums column 3. Using 0 as the second argument says use all rows. Here is some sample code: Sub SumArray() Dim rng As Range Dim v As Variant, v1 As Variant Set rng = Range("A1").CurrentRegion v = rng.Value v1 = Application.Index(v, 0, 3) For i = LBound(v1) To UBound(v1) Debug.Print v1(i, LBound(v1, 2)) Next Arraysum = Application.Sum(Application.Index(v, 0, 3)) Debug.Print Arraysum End Sub I believe this will limit you to an array of no larger than 5461 elements. If your array is bigger, I guess you will have to loop through you array and sum up the column yourself. -- Regards, Tom Ogilvy "ExcelMonkey " wrote in message ... How do you sum a particulate dimension in an array? That is I have a 2-D Array. I want to sum the 2nd dimension. Normally if it were 1-D I would go: ArraySum = Application.WorksheetFunction.Sum(Array) But if Array is a 2-D array, how do I qualify that I only want the 2nd dimension summed? --- Message posted from http://www.ExcelForum.com/ |
Applying Sum Function to 2nd Dimension of Array
Tom Ogilvy wrote:
I assume you mean a specifc column in the array. ArraySum = Application.Sum(Application.Index(Array,0,3)) the above sums column 3. Using 0 as the second argument says use all rows. . . . I believe this will limit you to an array of no larger than 5461 elements. If your array is bigger, I guess you will have to loop through you array and sum up the column yourself. Or, if the functions in the freely downloadable file at http://home.pacbell.net are available to your workbook: ArraySum = Application.Sum(ColumnVector(Array, 3)) The looping is pre-written into the ColumnVector function. Alan Beban |
All times are GMT +1. The time now is 01:39 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com