Worksheet Function of part of ARRAY

ronakv

New Member
Joined
Jul 8, 2015
Messages
7
Hi All,

I am running a percentile function on an array of data.
My array consists of Past 5 years of data & i am looking to calculate percentile on values for each year.
In Excel sheet, I could refer to the Rows for each year and do it. But now i have to create it as a function in VBA.

Is there a way by which i cam apply something like .Percentile(Array(365 to 730), 25%) ? (i.e. this is like calculating percentile for Second Year)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi
Welcome to the board

There are no vba native functions to extract part of an array.

The usual solution in this case is to create an auxiliary array with the values that you want and then process it.

There is, however, the possibility of using worksheet functions to get a part of the array (may have problems if more than 64k).

This is an example.

I load an array and a range with the same 1000 random values between 1 and 10000.
I then calculate the 25% percentile using a part of the range and the corresponding part of the array, and check that they are the same.

Try:

Code:
Sub Test()
Dim vArray(1 To 1000) As Long
Dim j As Long, k As Long

' Load some values in A1:A1000 and in the array for testing
For j = 1 To 1000
    k = Application.WorksheetFunction.RandBetween(1, 10000)
    Range("A" & j) = k
    vArray(j) = k
Next j

With Application
    MsgBox "Percentile 20% (200,600)" & vbNewLine & _
               "From Range: " & .Percentile(Range("A200:A600"), 0.25) & vbNewLine & _
               "From Array: " & .Percentile(.Index(vArray, [row(200:600)]), 0.25)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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