Results 1 to 10 of 10

Determining dynamic array length on a constant number of observations

Threaded View

lostest Determining dynamic array... 10-10-2015, 05:57 PM
shg Re: Determining dynamic array... 10-10-2015, 07:03 PM
lostest Re: Determining dynamic array... 10-11-2015, 10:48 AM
shg Re: Determining dynamic array... 10-11-2015, 01:16 PM
lostest Re: Determining dynamic array... 10-11-2015, 05:28 PM
shg Re: Determining dynamic array... 10-11-2015, 07:16 PM
lostest Re: Determining dynamic array... 10-12-2015, 06:17 AM
shg Re: Determining dynamic array... 10-12-2015, 01:27 PM
lostest Re: Determining dynamic array... 10-13-2015, 04:08 PM
shg Re: Determining dynamic array... 10-13-2015, 04:28 PM
  1. #1
    Forum Contributor
    Join Date
    10-10-2015
    Location
    the Dysfunctional Empire of Bulgaria
    MS-Off Ver
    2010
    Posts
    102

    Determining dynamic array length on a constant number of observations

    I am trying to calculate a trailing x-observation average on a column of data which includes both blank cells and non-blank cells.

    For example, I want to take the average of the last 3 observations of my data, but the number of blank cells keep changing so I need to redefine the array length each time.

    correct trailing average my loop
    2 n/a n/a
    3 n/a n/a
    4 n/a n/a
    <blank> 3 3 (2+3+4)/3
    <blank> 3 2.33 (3+4+0)/3
    7 3 1.33 (4+0+0)/3
    <blank> 4.66 2.33 (7+0+0)/3
    1 4.66 2.33 (0+7+0)/3
    <blank> 4 2.66 (1+7+0)/3
    2 4 2.66 (0+1+7)/3
    5 2.5 1 (2+0+1)/3
    6 2.66 2.33 (5+2+0)/3

    Let's say x is the number of observation I want to capture in my calculation.

    I have written this loop, but the problem is that it assumes my range length will always be equal to the number that the loop calculates the first time.
    I try to reset w = 0 outside the loop but I keep receiving an error message.

     s= -1
            Do Until w = x
            s = s + 1
                w = Application.WorksheetFunction.CountIf(Range(Sheets("Sheet 1").Cells(a - 1, b), Sheets("Sheet 1").Cells(a - x - s, b)), ">0")
                average = Application.WorksheetFunction.Average(Range(Sheets("Sheet 1").Cells(a - 1, b), Sheets("Sheet 1").Cells(a - x - s, b)))
            Loop
    Workbook example
    Attached Files Attached Files
    Last edited by lostest; 10-10-2015 at 08:18 PM. Reason: MOD WISDOM

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Aggregating a large number of observations
    By ssotirov in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-21-2015, 04:46 PM
  2. Determining a dynamic number from a range
    By smartdis in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-29-2014, 07:20 AM
  3. Help with Date Function determining length of employment between two dates
    By Troutner in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-05-2013, 10:59 AM
  4. [SOLVED] Fixed-length dynamic array: rolling computation
    By marcobm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2013, 01:15 PM
  5. Replies: 1
    Last Post: 02-20-2013, 07:57 PM
  6. Determining whether dynamic array has been used
    By MDW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2006, 09:50 PM
  7. [SOLVED] Determining number of values in an array (2 related questions)
    By KR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-04-2005, 06:06 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