+ Reply to Thread
Results 1 to 9 of 9

Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    I have been running in circles the past few days trying to write VBA code for a 14 day simple moving average that starts at the bottom of the worksheet instead of the top. I am extracting data from Yahoo and the most recent date is at the top of the page then descends downwards to the oldest date. Whatever I try to do, when I write the code using the average function, it always starts at the top of the worksheet and moves down

    I would like have the most recent date at the top because it is easier to read. Below is the code so far but I am even unsure if it is correct.

    i.e.

    5/20/16
    5/19/16
    5/18/16
    5/17/16

    etc..

    Please Login or Register  to view this content.

    Thankyou everyone in advance for looking at this. I have learned a lot on this forum along with trial and error.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,871

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    If your data is in column A (you didn't say):
    Please Login or Register  to view this content.
    For any date, this will give the average of the most recent 14 days ending on that date, which is generally how you would use a moving average. Note that you should really only fill down to LR-13, since dates earlier than that will not have 14 prior dates to average. That is, if your earliest date is 5/1/2015, then your earliest moving average date will be 5/14/2015. The dates from 5/1/2015 to 5/13/2015 will not have an average.

    I am puzzled as to why you need VBA for this since the formulas, once written, will never change. Is it because you will be adding more rows of data? If so, you could put the data in a table, then the formulas would be automatically filled down as new data is added.

    As is usually the case, providing your file would go a long way towards helping understand what you're trying to do.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    Hi Jeff,

    Thankyou much for your time. I intend to use the Average in a workbook consisting of 20 stocks in which I will
    update the prices everyday with the most recent DATE, OPEN, HIGH, LOW, CLOSE will be at the top of the spreadsheet.
    The Average should be calculated from the bottom up. Please see the attached file.

    Thankyou very much

    Joe
    Attached Files Attached Files

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,871

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    See if this gets you there. Note that you attached a csv file, which is data only. I had to save it as an Excel file to save formulas and add a macro.

    I don't understand what you mean by this:
    This is incorrect. The Moving Average should start at the bottom of the range instead of the top
    A two-week moving average for any given date is defined as the average of that date and the 13 days before that date. It doesn't make sense to talk about where it starts (bottom or top).

    You didn't specify what you wanted the average of so I used the closing price. I also added a macro with a button to insert a new row and fill in the formula for the average.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    I think this is the correct code for a 3 period SMA; I have been fiddling around with it and it seems to be correct but I am a little

    concerned with
    Please Login or Register  to view this content.
    I think I have this correct.

    Would the above mean 2 rows up from the very last row in a range and 2 columns from the left of the last column in a range ?

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    I saw your post in between my last reply . I like your solution, how do you change the moving average ?

    Thankyou very much for your time.

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    I added the formula year / month / weeknumber / day

    and after that I made a pivot table with the max of the Open per week.

    See the attached file.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,871

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    Quote Originally Posted by rmccain View Post
    I saw your post in between my last reply . I like your solution, how do you change the moving average ?
    Change it how? Change how many days it includes?

  9. #9
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top

    Thankyou very much for this and your time !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 15
    Last Post: 05-26-2016, 11:52 PM
  2. Moving down cells until date changes then calculate average
    By jfrank1034 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-02-2014, 12:26 PM
  3. Arranging Pivot table data from Newest to oldest to Newest does not appear
    By paradise2sr in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-08-2014, 06:53 AM
  4. [SOLVED] vba code to find Duplicate Values and Newest date(Max) date in the Corresponding Column(ce
    By Pradu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 05:20 AM
  5. Replies: 2
    Last Post: 08-05-2013, 02:41 PM
  6. Returning BLANK date PRIORITY before Newest/Latest Date
    By dluhut in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-11-2013, 04:43 PM
  7. [SOLVED] Help Calculating A Simple Moving Average
    By artiststevens in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-13-2013, 11:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1