Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applying function after filter is applied lacklustre Excel Worksheet Functions 4 October 11th 09 05:07 AM
MATCH Function - 2 Dimension Arrays AZ_Ray Excel Worksheet Functions 3 September 11th 08 10:59 PM
Using the sum function in a 3 dimension environment Paul Hargreaves Excel Discussion (Misc queries) 2 February 23rd 05 12:29 AM
single dimension array RobcPettit Excel Programming 3 January 20th 04 08:33 AM
Dimension problem APH Excel Programming 5 December 12th 03 11:23 PM


All times are GMT +1. The time now is 02:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"