Entender fórmula en vba, excel
Hola quisiera ayuda para entender una fórmula creada con un módulo en excel, la verdad quisiera poder entenderla ya que hay cosas que no entiendo, si alguien pudiera explicarmela estaría muy agradecida! Gracias!!
Function HoltWinter(alfa As Single, beta As Single, gama As Single, ventas As Range, estacionalidad As Range, Optional niveli As Variant, Optional tendenciai As Variant, Optional periodo As Variant)
Dim i As Integer, l As Integer
Dim S() As Single, Ft As Single, F As Single, T As Single, Tt As Single
Dim p As Integer
Dim formula As Single
Dim w1 As Single
Dim SesTot As Single
Dim Nestacionalidad As Integer
ReDim S(Nestacionalidad)
w1 = 0
' F = InitialLevel
' T = InitialTrend
If IsMissing(periodo) Then periodo = ventas.Rows.Count + 1
If estacionalidad.Rows.Count = 1 Then
Nestacionalidad = estacionalidad
Else: Nestacionalidad = estacionalidad.Rows.Count
End If
ReDim S(Nestacionalidad)
If IsMissing(tendenciai) Then
T = 0
Else: T = tendenciai
End If
If IsMissing(niveli) Then
w1 = 0
For i = 1 To Nestacionalidad
w1 = w1 + ventas.Cells(i, 1)
Next i
F = w1 / Nestacionalidad
Else:
F = niveli
End If
SesTot = 0
For i = 1 To Nestacionalidad
If ventas.Rows.Count = 1 Then
S(i) = ventas.Cells(i, 1) / (F + T)
Else
S(i) = estacionalidad.Cells(i, 1)
End If
If S(i) <= 0 Then
HoltWinter = " Value of any Seasonal Index should be greater than zero "
GoTo 0
End If
SesTot = SesTot + S(i)
Next i
If SesTot <> Nestacionalidad Then
For i = 1 To Nestacionalidad
S(i) = S(i) * (Nestacionalidad / SesTot)
Next
End If
If periodo <= Nestacionalidad Then
For i = 1 To periodo
formula = (F + T) * S(i)
Next i
Else
For i = 1 + Nestacionalidad To periodo
l = i Mod Nestacionalidad
If l = 0 Then
l = Nestacionalidad
Else: l = l
End If
p = WorksheetFunction.Max(periodo - (ventas.Cells.Count), 1)
formula = (F + p * T) * S(l)
If ventas.Cells(i, 1) = 0 Then
S(l) = S(l)
Else
Ft = alfa * (ventas.Cells(i, 1) / S(l)) + (1 - alfa) * (F + T)
Tt = beta * (Ft - F) + (1 - beta) * T
S(l) = gama * (ventas.Cells(i, 1) / Ft) + (1 - gama) * S(l)
End If
F = Ft
T = Tt
Next
End If
HoltWinter = formula
0
End Function