User Defined Function Error "subscript out of range"

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am writing a UDF to return array variants given the UDF subscript values. The UDF is below:

Code:
Function LogPriceData(Arr As Variant, numberObs As Integer) As Variant

Dim yy As Integer
Dim Array1() As Variant:        ReDim Array1(1 To numberObs)
Dim Array2() As Variant:        ReDim Array2(1 To numberObs)
Dim LogArray As Variant:        ReDim LogArray(1 To numberObs)


ActiveWorkbook.Sheets("ActiveSheet").Activate


For yy = 1 To numberObs


    Array1(yy) = Arr(numberObs, 2)


    Array2(yy) = Arr(yy, 2)
        
    LogArray(yy) = Application.WorksheetFunction.Log(Array2(yy), Array1(yy))


Next yy


LogPriceData = LogArray(yy)


End Function

I am receiving the "subscript out of range error on the last line:

Code:
LogPriceData = LogArray(yy)

The Function name is a variant as is LogArray. LogArray is Redim (1 to numberobs) whereas LogPriceData is not specified. What might be causing this error?
 

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
Code:
LogPriceData = LogArray([COLOR=#ff0000]yy-1[/COLOR])
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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