# VBA: Multi-dimensional array sum/mean/stdev

#### Ells_

##### Board Regular
I have a quick question that I couldn't quite find when searching for it.
I have a 3 dimensional array myArray(x,y,z), with x & y being input and z being output data in my case. I want to use different functions on myArray(x,y,, where : is all z values. example: cell(x,y) = sum(myArray(x,y,). I know I can do this with a (triple) loop, but I was wondering if there was an easier way to do this, since I know you can with 1-dimensional arrays

Thanks

### Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

#### shg

##### MrExcel MVP
Is it really a 3D array, or a 2D array (1 to n, 1 to 3)?

#### Ells_

##### Board Regular
Is it really a 3D array, or a 2D array (1 to n, 1 to 3)?

It is a 3D array. The first two dimensions are constant, and 3rd is the data itself. ex: myArray(1,1,data_points). The 3rd dimension is the same for every x and y.

#### shg

##### MrExcel MVP
I guess I'm missing what you're doing.

If you have a list of triplets {x,y,z}, you only need a 2D array to store it.

If you had a table with x values across the top, y values down the side, and z values in the body of the table, you would use 1D arrays for x and y, and a 2D array for z.

In any case, none of the worksheet functions will work on 3D arrays.

#### Ells_

##### Board Regular
I guess I'm missing what you're doing.

If you have a list of triplets {x,y,z}, you only need a 2D array to store it.

If you had a table with x values across the top, y values down the side, and z values in the body of the table, you would use 1D arrays for x and y, and a 2D array for z.

In any case, none of the worksheet functions will work on 3D arrays.

I guess I'll reword my description of my problem.
I have a myArray(x,y,z). If I input x and y, it will take the sum/average/stdev of all the z data of that x,y.

myArray(1,3,1) = 1
myArray(1,3,2) = 2
myArray(1,3,3) = 3

sum(myArray(1,3,1:3)) = 6
^ something that has this functionality is what I'm after. I just want to see if there's a way to do it without having to loop through everything

#### shg

##### MrExcel MVP
I know of no way other than a loop for 3D arrays. The worksheet functions you might use (e.g., Index, to get a slice of a 2D array) don't work on 3D arrays.

Replies
8
Views
209
Replies
3
Views
246
Replies
0
Views
154
Replies
5
Views
483
Replies
1
Views
380

1,195,936
Messages
6,012,396
Members
441,695
Latest member
MickRobertson

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back