Log Function Conversion VBA

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I would like to convert nominal data values into logarithmic values to understand rates of change. The data is in the form of an array and I would like to observe the log values given the first nominal value in the series compared to the current value. What formula can I use to do this if I want to incorporate a first value and a current value? The code I have thus far is below.

The code structure may be misleading. I anticipate using both variables Array1 and Array2 to define a currently undefined Log variable associated with the current value (array2).

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


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


For yy = 1 To numberObs


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


Next yy


End Function
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Can you show an example of input and expected results as it would appear on a worksheet?
 
Upvote 0
10/3/18835.8110/3/181.001396
10/2/18833.6010/2/181.001002
10/1/18828.0110/1/181

<tbody>
</tbody>
Sure,

The set of two columns on the left side are input type values and I would like to output values similar to the values in the set of two columns on the right.

The function I put together is below, but I'm getting an error on the LogArray(yy) line

Code:
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


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


LogArray = LogPriceData


End Function
 
Last edited:
Upvote 0
What are the inputs and what are the outputs? What is the calculation to arrive at the result?
 
Upvote 0
I used the worksheetfunction LOG() to produce the values. The first argument is the current value. The second argument is the base (first cell) written as $A$5

The inputs are taken from the left two columns the output is the right two columns.
 
Upvote 0

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,475
Latest member
Parik11

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