+ Reply to Thread
Results 1 to 4 of 4

Data Reduction using Rolling Average

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    us
    MS-Off Ver
    Excel 2003
    Posts
    3

    Data Reduction using Rolling Average

    I am try to reduce data using a rolling average. I am suppose to take the average of rows 1,2,4,5 and compare it to the middle row which is 3. If the average of rows 1,2,4,5 is greater than row 3 by more than 8 then I select it. I then continue the process this time if the average of rows 2,3,5,6 is greater than 4 then select it. I am trying to write a simple code which I need help. Some of my syntax might be wrong. I am a VBA newbie. I will like to copy the data to a different sheet. my code is incomplete


    Sub Macro1()
    Application.ScreenUpdating = False
    Sheets("Data").Select
    Lastrow = Range("A65536").End(xlUp).Row

    For t = 3 To Lastrow
    Sheets("Data").Select
    avg(t) = (cell(t-2,2) + cell(t-1,2) + cell(t+2,2) + cell(t+1,2))/4
    If ((avg(t)-cell(t,2))>=8) Or ((avg(t)-cell(t,2))>=-8) Then

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Data Reduction using Rolling Average

    Hi,

    please test this on your data:
    Please Login or Register  to view this content.
    Regards
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    04-18-2013
    Location
    us
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Data Reduction using Rolling Average

    It works but it only takes the average of the first 5 rows. I am trying to write a code that will calculate the rolling average of the rows from (1 to 5) then (2 to 6), (3 to 7) etc... when the average is calculated it will then be compared to the median row 3,4, and 5 respectively.If the median row is greater than the value 8 or -8 when compared to the average of the other rows, the median row is then copied to another sheet

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Data Reduction using Rolling Average

    Hi,

    please make sure to have a worksheet "Result" in the workbook where the avg will be written into columns A and B if the difference of the avg and the median is not greater than 8.
    Please Login or Register  to view this content.
    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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