VBA - price time series calcs on array - run time error 13

msaldut

New Member
Joined
Nov 17, 2014
Messages
8
0 down vote favorite
I suspect my question has a very simple answer, and yet I cannot find an answer that I understand in searching all over the site.


Ticker1 = an array of stock prices (1 To 2542)
PctChg1 = an array which I hope will ultimately hold the results of (Price_last / Price_prev)-1
i = counter


For i = 2 To UBound(Ticker1)
PctChg1(i, 1) = Ticker1(i, 1) / Ticker1(i - 1, 1) - 1
Next i


...something about the bold part it does not like - I have fooled around with ranges as well and cannot make sense of this. I don't know why it thinks I am dividing by a number that isn't there - if i am starting at point "2" (i=2) of the array, why wouldn't I be able to reference point "1" ?


Thanks so much in advance for your help.



<tbody>
</tbody>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi and welcome to the MrExcel Message Board.

I have had to guess how you have dimensioned your arrays but I have just tried this and it works OK.

Code:
Sub xxxx()

    Dim Ticker1(2542, 1) As Double
    Dim PctChg1(2542, 1) As Double
    Dim i As Long
    
    For i = 1 To 2542
        Ticker1(i, 1) = 100
    Next
    
    For i = 2 To UBound(Ticker1)
        PctChg1(i, 1) = Ticker1(i, 1) / Ticker1(i - 1, 1) - 1
    Next i

    Debug.Print UBound(Ticker1)
    
End Sub

I think Error 13 is a Type mismatch so are both arrays numeric?
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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