VBA: Multidimentional Array Syntax for STDEV Evaluation

pdevito3

Board Regular
Joined
Dec 17, 2013
Messages
246
So I have a two dimensional array. I want to get the standard deviation of all of the second dimensions values for each first dimension. So for example:
itemArr(1 to 3, 1 to 2)
{20, 40
30, 60
40, 80}

Stdev(20,40) = 14.14214
Stdev(30,60) = 21.2132
Stdev(40,80) = 28.28427


I have tried this simple example with a 1D array with success:
If I had the below array and code, it would run just fine.
Code:
 finalStdDev = WorksheetFunction.StDev(itemArr)
itemArr(1 to 3)
{20
40
60}
Stdev(20,40,60) = 20

But I am not sure what the syntax is for trying it in 2D:
With the below example where eachItem is an integer to reference an array dimension, I don’t know the proper syntax for executing this
Code:
finalStdDevArr(eachItem) = WorksheetFunction.StDev(itemArr(eachItem),1 to itemCountArr(eachItem))
itemArr(1 to 3, 1 to 2)
{20, 40
30, 60
40, 80}

Stdev(20,40) = 14.14214
Stdev(30,60) = 21.2132
Stdev(40,80) = 28.28427

This attempt will potentially get my point across but I can definitely explain another way and/or in more detail if needed.

Appreciate any input. Thanks in advance.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
try this


Code:
Sub stDev1()
Dim myArray(1 To 3, 1 To 2) As Long


myArray(1, 1) = 20
myArray(1, 2) = 40
myArray(2, 1) = 30
myArray(2, 2) = 60
myArray(3, 1) = 40
myArray(3, 2) = 80


MsgBox WorksheetFunction.StDev(WorksheetFunction.Index(myArray, 1, 0))


MsgBox WorksheetFunction.StDev(WorksheetFunction.Index(myArray, 2, 0))


MsgBox WorksheetFunction.StDev(WorksheetFunction.Index(myArray, 3, 0))
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,114
Messages
6,134,722
Members
449,886
Latest member
MD SHIBLI NOMAN NEWTON

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top