Type Mismatch

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am working with a User Defined Function to transform an array of nominal integer values to logarithms. I have the code below.

LogArray is a variant and I suspect this data type does not work with the integer values being fed into the worksheetfunction.

How can I build the array to hold log values?

Code:
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'X  This UDF converts an array of nominal values into an array of logarithmic values    X
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


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


Dim yy As Integer
Dim Array1 As Integer
Dim Array2 As Integer
Dim LogArray As Variant


ActiveWorkbook.Sheets("ActiveSheet").Activate


Array1 = Application.WorksheetFunction.Index(Arr, 1, 2)


For yy = 1 To numberObs


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


Next yy


LogPriceData = logarray()


End Function
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
Dim Array1() as Variant, Array2() as Variant, LogArray() as Variant
HTH. Dave
ps. It also seems that numberobs should be a double?
 
Upvote 0
Thanks!

I have one more error also a mismatch on the line

Code:
Array1() = Application.WorksheetFunction.Index(Arr, 1, 2)

Array1 is now a variant, Arr is a variant as well, however the Index worksheet function is going to return a single value at column 2 row 1. My intention is to define array1 as a series of values defined by the index value for each observation in the space yy. Do you know how I might be able to create array1 with these characteristic?
 
Upvote 0
I really don't understand your use of index or what "space yy" is? Arrays have positions to fill. Your Arr should also indicate a position ie. Arr(0). Here's a general outline...
Code:
For cnt = 0 to totalobs - 1
Array1(cnt) = Application.WorksheetFunction.Index(Arr, 1, 2)
Next cnt
Maybe a bit more info. Dave
 
Last edited:
Upvote 0
Try adding this to your original code:

Code:
Redim LogArray(1 to numberObs)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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