+ Reply to Thread
Results 1 to 9 of 9

Dynamic range in average formula

  1. #1
    Forum Contributor
    Join Date
    04-19-2009
    Location
    Toulouse, France
    MS-Off Ver
    Excel 2010
    Posts
    130

    Question Dynamic range in average formula

    Hello all,

    Please excuse the above title I was at a loss of what to call this one.

    I have the following incomplete code...

    Please Login or Register  to view this content.


    i could finish it but have many more ranges to go and was wondering if there was a shortcut my guess is yes. As you can see in the above code (fairly banal i know) im pulling averages of data from sheet 2 and putting them into what will be a table on sheet 3. I could go through and do them individually but that would be quite painful. Does somone a little more technically minded know of any tricks to expedite the process ie shorten the code. would be handy if it was applicable to other formulas also
    thanks for your help

    Dan

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Dynamic range in average formula

    Hi Dan,

    Does the following help

    Please Login or Register  to view this content.
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    04-19-2009
    Location
    Toulouse, France
    MS-Off Ver
    Excel 2010
    Posts
    130

    Smile Re: Dynamic range in average formula

    Thankyou Richard works a treat, do you mind explaining some of that for me if you have some time so i can duplicate that for different problems in the future instead of bugging you guys. Would be much appreciated. thanks again

    Regards
    Dan

  4. #4
    Forum Contributor
    Join Date
    04-19-2009
    Location
    Toulouse, France
    MS-Off Ver
    Excel 2010
    Posts
    130

    Re: Dynamic range in average formula

    Ah was wondering what that notation was, just found a few sites explaining R1C1 notation will this help in lifting the veil?

    Dan

    Ps in my original post said notation was automated by recording a macro.

  5. #5
    Forum Contributor
    Join Date
    04-19-2009
    Location
    Toulouse, France
    MS-Off Ver
    Excel 2010
    Posts
    130

    Question Re: Dynamic range in average formula

    Hello

    on closer look sorry last time had a brief look it is returning values but not from the ranges that i want, it is several cells out of whack. eg where i want the average from I53:I57 it is instead returning I51:I55 as i don't understand what has been written I can't make the appropriate adjustments.Can someone give me a quick heads up on the choice of numbers in the ranges and the role of * and + in those ranges. If anyone can help on this would be much appreciated

    Regards
    Dan
    Last edited by Cicada; 05-09-2011 at 11:14 AM.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Dynamic range in average formula

    Hi Dan,

    The Input box prompts for the number of iterations. Your original example used four, but in the real world rather than prompt for a number you'd may be able to use a system variable which identifies the number of iterations from a list of values.

    I left the first formula as the RC notation since I didn't seem to fit in with the rest of the example. I generally prefer to use the A1 notation, hence the rest of the code.

    The two columns you're using (B & C) are hard coded but again for a generalised solution you may be able to generate those with variables which work out the columns to use.

    The x variable is a loop counter and is set by the answer to the input box. In your example the various ranges that you're averaging are 9 rows apart, hence the hard coded reference to '9' in the Excel formula. So for instance in the first iteration where x = 1, the code

    Please Login or Register  to view this content.
    multiples 1 by 9 and adds 33 to set the start of the range to row 42, and the end of the range to 1 x 9 plus 37, i.e. 46. The column is hard codes as "I"

    On the second iteration, x =2 and hence 2 x 9 + 33 = 51 which is the start of the second range.

    etc...

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Dynamic range in average formula

    Hi Dan,

    Sorry, the starting point of the ranges was wrong. Substitute the following two lines in the For..Next loop

    Please Login or Register  to view this content.
    Regards

  8. #8
    Forum Contributor
    Join Date
    04-19-2009
    Location
    Toulouse, France
    MS-Off Ver
    Excel 2010
    Posts
    130

    Smile Re: Dynamic range in average formula

    Legend, thanks Richard for your time.

    Many thanks
    Dan
    Last edited by Cicada; 05-09-2011 at 01:35 PM.

  9. #9
    Forum Contributor
    Join Date
    04-19-2009
    Location
    Toulouse, France
    MS-Off Ver
    Excel 2010
    Posts
    130

    Re: Dynamic range in average formula

    sorry to bug you again Richard why in the second iteration does x = 2 what is this a function of?

    Regards
    Dan

    Disreard sorry was having a vague moment
    Last edited by Cicada; 05-09-2011 at 02:11 PM.

+ 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