Stopped working, not sure why

ajc5382

New Member
Joined
Jun 25, 2012
Messages
41
Below is code for my volatility calculation.

rngvol is the number of days the volatility is taken over
volcal is the number of data items
cor1 is the standard deviation over a given range
volatility 1 should be the volatilty result

'Statistical Volatility Calculation 1




rngvol = Worksheets("config").Cells(32, 2)
volcalc = WorksheetFunction.CountA(Sheets("INFO").Range("A:A"))


Do Until Worksheets("info").Cells(rngvol + i + 1, 1).Value = ""
For i = 1 To volcalc - rngvol + 1
cor1 = WorksheetFunction.StDev(INFO.Range(INFO.Cells(2 + i, 4), INFO.Cells(rngvol + i + 1, 4)).Value)
volatility1 = cor1 * Worksheets("config").Cells(38, 2).Value
Worksheets("info").Cells(rngvol + i + 1, 8).Value = volatility1

Next i
Exit Do


Loop
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Is there any code before the code you posted?

You could start by posting that instead of the whole thing.
 
Upvote 0
I have isolated the error to a range issue. What is happening is that the code is calculating the %difference, however, at the end of the data it is using to make there calculations, there are several values that are 0. Thus, the the Overflow Error. I've tried many things but they all seem to have some sort of issue. Any suggestions as far as how to handle situations when the calculation is using bad data or how to stop the calculation once cells equal 0 or are empty
 
Upvote 0
So the error is one you would get if you used the formula on a worksheet?
 
Upvote 0
I'm guessing yes. What I'm working on now is a loop of some sort that will stop the calculation when the cell is void or is 0. This is what I have so far, I can't get it to work..

Code:
    '%Change 1


Drows = WorksheetFunction.CountA(Sheets("INFO").Range("A:A"))
 


Do
   For r = 1 To (Drows - 1)
     newval1 = Worksheets("INFO").Cells(2 + r, 2).Value
     old1 = Worksheets("INFO").Cells(1 + r, 2).Value


     percentchange1 = (newval1 - old1) / old1
     Worksheets("info").Cells(2 + r, 4).Value = percentchange1
    Next r
Loop Until Worksheets("info").Cells(1 + r, 2).Value = "0" Or ""

Cheers
 
Upvote 0
Sorry, this is the code I'm trying to get to work.


'%Change 1


Drows = WorksheetFunction.CountA(Sheets("INFO").Range("A:A"))



Do
For r = 1 To (Drows - 1)
newval1 = Worksheets("INFO").Cells(2 + r, 2).Value
old1 = Worksheets("INFO").Cells(1 + r, 2).Value


percentchange1 = (newval1 - old1) / old1
Worksheets("info").Cells(2 + r, 4).Value = percentchange1
Next r
Loop Until Worksheets("info").Cells(1 + r, 2).Value = "0" Or ""

[/code]
 
Upvote 0
Try this,
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Drows = WorksheetFunction.CountA(Sheets("INFO").Range("A:A"))
For r = 1 To (Drows - 1)
    newval1 = Worksheets("INFO").Cells(2 + r, 2).Value
    old1 = Worksheets("INFO").Cells(1 + r, 2).Value
    If old1 = 0 Then Exit For
    percentchange1 = (newval1 - old1) / old1
    Worksheets("info").Cells(2 + r, 4).Value = percentchange1
Next r
[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,216,111
Messages
6,128,899
Members
449,477
Latest member
panjongshing

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