PDA

View Full Version : VBA Exponential Smoothing



crkennedy
12-01-2020, 06:47 AM
I'm trying to create a function for implementing simple exponential smoothing in this VBA spreadsheet.
I've gotten code I've amended from online to suit my needs but it's running incorrectly, it only pastes 0's in column C.
Could anyone advise?


Sub ExpSmoothing()
Dim y As Double
Dim Lastyhat As Double
Dim Currentyhat As Double
Dim i As Integer
Dim alpha As Variant


alpha = Application.InputBox("What is your alpha value?")


If alpha > 0 And alpha < 1 And IsNumeric(alpha) Then
With Worksheets("Data")
.Range("C1").Value = "Exp Smoothing"


For i = 1 To 15


.Range(.Cells(i + 1, 3), .Cells(14, 3)).Value = y


.Range("C2" & i).Value = Lastyhat


Currentyhat = Lastyhat + (alpha * (y - Lastyhat))


Lastyhat = Currentyhat


.Range("C" & i + 1).Value = Currentyhat




Next i
End With
Else
MsgBox ("Please choose an alpha that is numeric and between 0 and 1")
End If
End Sub

Paul_Hossler
12-01-2020, 09:21 AM
Can you post a workbook with sample data?

snb
12-02-2020, 02:29 AM
Variable y seems to be discarded.

SamT
12-03-2020, 09:22 AM
All the math in your loop always results in zeros

snb
12-03-2020, 10:01 AM
At least that seems very smooth indeed.

SamT
12-03-2020, 10:22 AM
oo0000o0o0oo000

paulpk
12-04-2021, 04:11 PM
HEY BUddy I'm also facing similar problem, if got the solution for this can you please guide me
please reply as soon as possible
thank you

Aussiebear
12-04-2021, 08:03 PM
@paulkpk. Where does one start? Same problem as SamT "ooOOOOoOoOooOOO" or "All the math in your loop will end in Zeros", or snb who thinks "Variable Y seems to be discarded" or "it seems very smooth indeed", Paul_Hossler who is wanting a sample book to be provided, or the OP of this old thread?

It always amazes me that people jump unto old threads, provided very little in way of supporting information, and demand that someone replies as soon a possible. I'm assuming you have at least read this thread before posting, and from that you can reasonably see that no solution was found since those wanting to assist were waiting for the OP to supply further detail. Which brings me to the second point, since there is clearly very little supporting data why would you not provide a workbook sample to allow others to assist you. Thirdly, it would be extremely helpful if you could indicate what your own efforts so far have achieved.

snb
12-05-2021, 03:56 AM
@AussieB

I fully agree.
But I fear that, considering paulpk's national flag, it's 'pearls before swine'.