+ Reply to Thread
Results 1 to 7 of 7

Offset, Arrays, and more Offset

Hybrid View

  1. #1
    Registered User
    Join Date
    05-07-2013
    Location
    HAN, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Offset, Arrays, and more Offset

    Hello Excel experts!

    I'm a long time reader, first time poster. Please be gentle I'm running this in Windows on Excel 2007.

    I'm looking to see if this is possible using Excel formulas, rather than a VBA solution. If this is too complicated for formulas, let me know.

    I have some annual data, which does not start in A1. The data is created by some previous spreadsheet formulas on the worksheet, so I can't relocate it.

    Year values in row 85 go back to 2000, counts in row 86 go back that far as well. Future years have blank entries. Here is an example of what it looks like:
    N O P Q R S T U V W X Y Z
    85 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
    86 30 18 12 35 45 8 17

    I also have some control cells, which are the core of the table generation:
    M80 (target year): 2010
    M81 (spread): 2
    M82 (window): 4

    The purpose is to create a DYNAMIC TABLE that is "window" years wide starting with the target year. The header row would be calendar years. This header row for this example would be
    2010 2011 2012 2013
    These could start anywhere. For this example, destination for the start of this range would be Q90 (i.e. Q90 :=2010).

    The values to be placed in the dynamic table (starting at Q91) would be:
    The cumulative sum from the start of the values up to the "target year +1", divided by the "spread". i.e. =SUM($G$86:Q86)/M81.
    This same value repeated a second time (since spread is 2). i.e. =SUM($G$86:Q86)/M81.
    The remaining years (Window - spread) contain the values under the year.

    The end result I would want is
    2010 2011 2012 2013
    =SUM($G$86:Q86)/M81 =SUM($G$86:Q86)/M81 =R86 =S86
    47.5 47.5 45 8

    The dynamic table changes (i.e. grows or shrinks) based on the parameters (start year, window, spread).

    I managed to manually insert an offset array function for the "non cumulative" years, but I get #N/A errors since my destination array is larger (except for the largest window sizes) than my results. I did this via the select range, press F2, enter formula, CTRL+SHIFT+ENTER.

    Like I said at the start - this is complex and I could write some VBA code to handle it, but I'd like to try a formulaic approach first.

    Thanks for listening! I look forward to your responses
    Last edited by lucholland; 03-11-2014 at 02:47 PM. Reason: received a complete solution

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Offset, Arrays, and more Offset

    Okay, question 1.
    Why does it start in Q90? Because 2010 is in P? (i.e. starts 1 to right of target year)? or just random choice?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    05-07-2013
    Location
    HAN, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Offset, Arrays, and more Offset

    Quote Originally Posted by ChemistB View Post
    Okay, question 1.
    Why does it start in Q90? Because 2010 is in P? (i.e. starts 1 to right of target year)? or just random choice?
    Hey ChemistB,

    Semi random choice. Not significant/important except it ensures if the table grows to the right nothing gets overwritten.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Offset, Arrays, and more Offset

    Okay, here's what I came up with. I gave named ranges to your target, spread and window. I also defined a "datatable" named range as follows

    Formula: copy to clipboard
    =Sheet1!$F$85:INDEX(Sheet1!$86:$86,COUNT(Sheet1!$86:$86)+COLUMN(Sheet1!$E86))
    because your years (at least in my sheet) begin in column F.

    In Q90
    = Target
    In R90 copied to the right
    =IF(COLUMN()-COLUMN($Q$90)>=Window,"",Q90+1)

    In Q91 copied to the right
    Formula: copy to clipboard
    =IF(COUNT(P$90:$Q90)=Window,"", IF(COUNT($Q$90:Q90)>Spread,HLOOKUP(Q90,datatable,2,FALSE), SUM($F$86:INDEX(86:86,MATCH($Q$90,85:85,0)+1))/Spread))
    See attachment.
    Does that work for you?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-07-2013
    Location
    HAN, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Offset, Arrays, and more Offset

    I'm amazed!!

    From my quick test I ran on the attached file, it appears to work exactly as needed. Later today, I'll go through additional test scenarios to confirm.

    I'm impressed with the elegance of the solution, too. Very nice work!

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Offset, Arrays, and more Offset

    Thank you. Hope it all works out.

  7. #7
    Registered User
    Join Date
    05-07-2013
    Location
    HAN, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Offset, Arrays, and more Offset

    Quote Originally Posted by ChemistB View Post
    Thank you. Hope it all works out.
    Follow-up: ran through my 10 test cases, and they all worked perfectly.

    Thank you for the solution. I was so focused on using OFFSET, I ignored other solutions.

+ 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. function similar to offset to offset the offset
    By Jerseynjphillypa in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-03-2012, 03:07 PM
  2. [SOLVED] offset multiple arrays
    By mammagamma in forum Excel General
    Replies: 9
    Last Post: 07-03-2012, 01:48 PM
  3. Reformatting - insert formula with offset, then offset to next cell
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2011, 05:41 AM
  4. Replies: 7
    Last Post: 11-04-2008, 06:41 AM
  5. [SOLVED] Use of offset and match functions with changing arrays, I think???
    By Prohock in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-15-2006, 01:20 PM

Tags for this Thread

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