Apply an excel function to a column in a matrix

camqui

New Member
Joined
Feb 8, 2016
Messages
5
Hi everybody

I'm looking for some help applying the standard deviation to one column in a matrix, I don't know the right way to define the range in this formula, so I will put an example for a better explanation of what I intend to do:


Option Base 1

Sub Producto()


ReDim c(6, 2) As Variant


c(1, 1) = 10
c(1, 2) = 15
c(2, 1) = 17
c(2, 2) = 74
c(3, 1) = 16
c(3, 2) = 83
c(4, 1) = 75
c(4, 2) = 15
c(5, 1) = 78
c(5, 2) = 54
c(6, 1) = 26
c(6, 2) = 56


Dim e As Double


e = application.WorksheetFunction.StDev_P(c(1,1):(6,1))




End Sub


When I hit enter after typing <e = application.WorksheetFunction.StDev_P(c(1,1):(6,1))> There's a message displying a compilation error: "Expected: list separator or )" and the code highlight the ":"

This is an example so I can't define item by item to apply this function. I hope you've understood me and I will thank a lot anyone who help me[h=3][/h]
 
All you need to do is pass the matrix/array to the function.
Code:
e = Application.WorksheetFunction.StDev_P(c)
 
Upvote 0
Hi, thanks for your help. The number of columns in the matrix is variable since it will be a selection, so: How can I split a matrix of n columns to n arrays? where n is variable?
 
Upvote 0
Are the columns to be passed to the function contiguous?
 
Upvote 0
It should be straightforward then, to get the appropriate range we can use offset and resize.
 
Upvote 0
If you have an array, myArray, this will return the n'th column of myArray

Code:
msgBox  Worksheetfunction.StDevA(WorksheetFunction.Index(myArray, 0, n))
 
Upvote 0

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