Consulting

Results 1 to 9 of 9

Thread: VBA Exponential Smoothing

  1. #1

    VBA Exponential Smoothing

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Posts
    8,098
    Location
    Can you post a workbook with sample data?
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,281
    Variable y seems to be discarded.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,704
    Location
    All the math in your loop always results in zeros
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,281
    At least that seems very smooth indeed.

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,704
    Location
    oo0000o0o0oo000
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Newbie
    Joined
    Dec 2021
    Posts
    1
    Location

    HEY BUddy I'm also facing similar problem, if got the solution for this can you pleas

    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

  8. #8
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    3,916
    Location
    @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.
    Remember To Do the Following....
    Use tags when posting code to the thread,
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  9. #9
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,281
    @AussieB

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •