Pls, I am new to VBA. I copy this script below from a book on how to calculate standard deviation on a data in a sheet and record in separate column.
The problem I am having is that the script is not running. Please, what could be the reason? Or rather help me modify it. Thanks.
The code:
Dim WindowlLength As Integer
Dim StdDevRange As Range

WindowLength = 20

'Column headings
Cells(1, "A") = "Symbol"
Cells(1, "B") = "Date"
Cells(1, "E") = "Close"
Cells(1, "F") = "Price Change"
Cells(1, "G") = "Log Change"
Cells(1, "H") = "Spike"

'Calculate price change and log of price change
DataRow = 3
While Cells(DataRow, "A") <> ""
If Cells(DataRow, "A") = Cells(DataRow - 1, "A") Then
Cells(DataRow, "F") = Cells(DataRow, "E") / Cells(DataRow - 1, "E")
Cells(DataRow, "G") = Log(Cells(DataRow, "E") / Cells(DataRow - 1, "E"))
End If
DataRow = DataRow + 1
Wend

'Calculate price spikes in standard deviations
DataRow = WindowLength + 3
While Cells(DataRow, "A") <> ""
If Cells(DataRow, "A") = Cells(DataRow - _
WindowLength - 1, "A") Then
Set StdDevRange = Range("G" & (DataRow - _
WindowLength) & ":" & "G" & (DataRow - 1))
Cells(DataRow, "H") = Cells(DataRow, "F") / _
(Application.WorksheetFunction.StDev(StdDevRange) _
* Cells(DataRow - 1, "E"))
End If