PDA

View Full Version : part of code to slow?!



amateur1902
03-14-2008, 04:13 AM
Hello everyone,

I've got a question about a part of the code i use. When i run the code it takes 8 seconds to end en the part that is following takes 6 seconds of it.

I know that this part needs time to process but do you think that it can go any faster.


Dim arrayCorrel() As Variant
ReDim arrayCorrel(nr_comp)

For a = 0 To nr_comp
For B = 0 To nr_of_dates
arr_Dp(B) = vtResult(B, a, 1)
Next

arrayCorrel(a) = Application.Correl(arr_Id, arr_Dp)

u = a - 1

If Not IsNumeric(arrayCorrel(a)) Then
arrayCorrel(a) = arrayCorrel(u)
End If


ReDim arr_Dp(nr_of_dates) As Variant

Next


This is just a small part of the whole code. But when i would give the full it can get blurry. I hope this info is enough for you to help.

When you need more info or a bigger part of the code. Please ask

Thanks

OTWarrior
03-14-2008, 04:19 AM
what exactly is this code trying to do? You have a loop within a loop, why is this needed? why are you rediming arr_Dp as a variant within a loop?

If I knew what you are trying to do, then I would understand the code better, and be able to help you.

amateur1902
03-14-2008, 04:26 AM
Hi,

I am calculating the correlation between stocks. When i put one stock in excell i want to calculate the correlation between him and the other stock that i have imported. The array ind. is the stock that stays the same. And the array dependent changes during the proces.

This is te first loop.

Then it is possible that a stock doesn't have any data on the date excel wants to. Then the loop says pick up the previeus data and go on.

this is te second loop.

I read on internet that loops can slow down vba. But i have realy no idea how to make this part go faster.

I hope it is clear now.

Thanks