I can't discover what is wrong in my code.
ArraySeasonality(M) is constantly saying that the subscript is out of range, yet I let M (it was I before but I tried a different variable, still didn't work) loop from 0 to 3 and ArraySeasonality has 4 datapoints (0,1,2,3)
It is probably something I do wrong in the way I write the loops. When I remove the I=0 lines then the other variables show the subscript out of range as well.
'All Declarations
Dim Startrow As Long 'row begin variable
Dim Endrow As Long 'row end variable
Dim ColumnForecasting As Integer
Dim I As Long
Dim M As Long
Dim ArrayDemand(7) As Single
Dim ArrayNewSeries(7) As Single
Dim ArraySmoothedDemand(7) As Single
Dim ArraySeasonality(3) As Variant
Dim VarNew As Integer
Dim VarDesDemand As Single
Dim VarMovingAverage As Single
Dim VarSmoothedMovingAverage As Single
Dim VarMovingstdv As Single
Dim VarSmoothedDemand As Single
Dim VarMovingAverageSeasonality As Single
Dim VarRunrate As Single
'Timestamp
Range("A1") = Now()
Startrow = 16
Endrow = Range("E7").End(xlDown).Row - N
'Current row to last row
For N = Startrow To Endrow
'Deseasonalizing demand
VarDesDemand = Cells(N, 5) / Cells(N, 11)
I = 0
For I = LBound(ArrayNewSeries) To UBound(ArrayNewSeries)
ArrayNewSeries(I) = Cells(N - I, 7)
Next I
'Check if 8 periods are known since beginning of new series
If WorksheetFunction.Sum(ArrayNewSeries) = 0 Then
'Retrieving last 8 deaseasonalized demand points
I = 0
For I = LBound(ArrayDemand) To UBound(ArrayDemand)
ArrayDemand(I) = Cells(N - I, 30)
Next I
'Taking the moving average and moving standard deviation
VarMovingAverage = WorksheetFunction.Average(ArrayDemand)
VarMovingstdv = WorksheetFunction.StDevP(ArrayDemand)
'Smoothing the demand with upper and lower bound
Select Case ArrayDemand(0)
Case Is >= VarMovingAverage + VarMovingstdv
VarSmoothedDemand = VarMovingAverage + VarMovingstdv
Case Is <= VarMovingAverage - VarMovingstdv
VarSmoothedDemand = VarMovingAverage - VarMovingstdv
Case Else
VarSmoothedDemand = ArrayDemand(0)
End Select
Cells(N, 33) = VarSmoothedDemand
'Runrate
I = 0
For I = LBound(ArraySmoothedDemand) To UBound(ArraySmoothedDemand)
MsgBox (I)
ArraySmoothedDemand(I) = Cells(N - I, 33)
Next I
M = 0
For M = LBound(ArraySeasonality) To UBound(ArraySeasonality)
ArraySeasonality(M) = Cells(N + 1 + M, 11)
Next M
VarSmoothedMovingAverage = WorksheetFunction.Average(ArraySmoothedDemand)
VarMovingAverageSeasonality = WorksheetFunction.Average(ArraySeasonality)
VarRunrate = VarSmoothedMovingAverage * VarMovingAverageSeasonality
Else
VarMovingAverage = 0
VarMovingstdv = 0
VarSmoothedDemand = 0
VarRunrate = 0
End If
Cells(N, 30) = VarDesDemand
Cells(N, 31) = VarMovingAverage
Cells(N, 32) = VarMovingstdv
Cells(N, 34) = VarRunrate
Next N
Bookmarks