+ Reply to Thread
Results 1 to 28 of 28

non constant arrays?

  1. #1
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    non constant arrays?

    I'm trying to do the following in the formula bar:

    ={A1+A2,A2-A1,A3+A4}, but it doesn't let me. Seems I only use constants?

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: non constant arrays?

    what are you trying to do? cant you just
    =SUM(A1+A2,A2-A1,A3+A4) or are you trying to create an array say {3,1,7} for use in another function?
    Last edited by martindwilson; 06-28-2010 at 03:10 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Trying to create the array {A1+A2, A2-A1, A3+A4}
    Last edited by shg; 06-28-2010 at 11:43 AM.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: non constant arrays?

    yes but for what use?

  5. #5
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    well mainly for feasibility and so I don't have to setup multiple worksheets just to set up the arrays. Right now I have a seperate sheet that is used more or less exclusively to set up data for me to use in arrays,if I had the ability to just create arrays on the fly ie. {A1+A2,A3-A4,A5+A2}, etc. as opposed to doing Sheet2!A1:A3 where Sheet2!A1 = A1+A2, Sheet2!A2 = A3-A4, Sheet2!A3 = A5+A2

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: non constant arrays?

    hmmmmmm that has me stumped.
    possibly via vba
    ok anyone else got an offer?

  7. #7
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    BUMP

    anyone? there has to be a neat way of doing this

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    Please Login or Register  to view this content.
    =Agg(A1+A2, A2-A1, A3+A4)
    Entia non sunt multiplicanda sine necessitate

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

    Re: non constant arrays?

    Note: If you wish to see the individual values of Shg's function, then it can be entered as an array, select the number of cells = to the number of arrays you are calculating. Enter with CNTRL SHFT ENTER

    Hope that helps.
    Last edited by ChemistB; 07-02-2010 at 12:38 PM. Reason: Modified after DO's explaination
    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

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: non constant arrays?

    I think shg's post is more to illustrate how all three results are returned in a single 1D Array (you see only the first value in the cell however all three exist - eg SUM(Agg(...)) would return the aggregate of the Array).

    The same can be achieved using formulae but it is significantly less flexible:

    =INDEX(CHOOSE({1,2,3},A1+A2,A2-A1,A3+A4),0)

    (same point holds - ie you see one value but all exist within [highlight and press F9 or again see: SUM(INDEX(...)) which would aggregate the 1d array])

    The native approach is less flexible given the {1,n} would need to be adjusted based on the number of arguments supplied in the CHOOSE whereas shg's UDF utilises a ParamArray and thus will adjust dynamically

  11. #11
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Donkey

    unfortunately your method does not actually return an array, it returns a number within an array (sort of like a read command like array[5]). I'm looking for something actually returns an array, ie. similar to row(), column(), etc.

    Unforunately the mac2008 version of excel i'm using does not support VBA =(

    What I'm ultimately trying to do is:

    I have a large n x m matrix of percentages, from E8 to I12

    I need to create an array {(1-E8)*(1-F8)*...*(1-CURRENTCOLUMN8) , (1-E9)*(1-F9)*...*(1-CURRENTCOLUMN9) , ... , (1-E12)*(1-F12)*...*(1-CURRENTCOLUMN12)}

    and multiply this huge array by another array
    Last edited by themachine; 07-05-2010 at 11:09 AM.

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: non constant arrays?

    Quote Originally Posted by themachine
    Donkey

    unfortunately your method does not actually return an array, it returns a number within an array
    Please read my post again, specifically:

    Quote Originally Posted by D.O
    ie you see one value but all exist within [highlight and press F9 or again see: SUM(INDEX(...)) which would aggregate the 1d array]
    If you're ever unsure as to what is being returned be sure to make use of the F9 feature in the Formula Bar - ie highlight the INDEX function and press F9 - you will see the array of results.

    A cell will only ever display a single result - whereas in fact the INDEX holds all values by virtue of the 0 row_index - do not confuse cell content with formula "output".

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    Unforunately the mac2008 version of excel i'm using ...
    That would be a good thing to have in your profile, rather than Excel 2007.

  14. #14
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Quote Originally Posted by shg View Post
    That would be a good thing to have in your profile, rather than Excel 2007.
    sorry I have 2008 MAC at work, 2007 at home

  15. #15
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Quote Originally Posted by DonkeyOte View Post
    Please read my post again, specifically:



    If you're ever unsure as to what is being returned be sure to make use of the F9 feature in the Formula Bar - ie highlight the INDEX function and press F9 - you will see the array of results.

    A cell will only ever display a single result - whereas in fact the INDEX holds all values by virtue of the 0 row_index - do not confuse cell content with formula "output".
    Problem is when I try and do something like C1:C3*INDEX(CHOOSE({1,2,3},A1+A2,A2-A3,A3+A2),0) the INDEX() part is the same value, ie. it doesn't change to A2-A3, A3+A2, etc.
    Last edited by themachine; 07-05-2010 at 11:45 AM.

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    If you select D1:D3 and array-enter the formula, you'll see all three values returned.

  17. #17
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    I'm pretty sure array multiply doesn't do it:

    http://i.imgur.com/tCGgt.png

    A5:A7 were array formula entered, but they should be:

    177
    440
    305

    Where as they are:

    177=(A1+A2)*3
    236=(A1+A2)*4
    295=(A1+A2)*5

    SUM() does seem to iterate over the index and work as intended, but Array multiply certainly doesn't
    Last edited by themachine; 07-05-2010 at 11:57 AM.

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    That formula generates 9 results. Maybe what you're looking for is

    =C1:C3*CHOOSE({1;2;3}, A1+A2, A1+A1, A3+A1)

    Note the semicolons in lieu of the commas to make the second array a column array.

  19. #19
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Ahh, I see what you mean. It was creating a 3x3 matrix

    {1;2;3} is a column array where as {1,2,3} is a row array?
    Last edited by themachine; 07-05-2010 at 12:13 PM.

  20. #20
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    The latter is a row array; neither is more 'normal' than the other.

  21. #21
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Many thanks for the help,

    Using this technique, I'm trying to make the array

    {PRODUCT(E8:F8),PRODUCT(E9:F9),...,PRODUCT(E99:F99)}

  22. #22
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    No need for any of that; =E8:E99*F8:F99, array-entered.

  23. #23
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Quote Originally Posted by shg View Post
    No need for any of that; =E8:E99*F8:F99, array-entered.
    Sorry I wasn't specific enough, unfortunately I need to be able to drag/expand at will

    Column 1:

    {PRODUCT($E8:F8),PRODUCT($E9:F9),...,PRODUCT($E99:F99)}

    allows me to drag it to the next column to create

    Column 2:

    {PRODUCT($E8:G8),PRODUCT($E9:G9),...,PRODUCT($E99:G99)}

    I'm really trying to create this

    http://i.imgur.com/5HXgw.jpg

    Essentially a weighted average of risk reductions scalable across multiple components and reducable by percentages. My implementation is kinda disgusting, as I have 2 other sheets used mainly to just store data for taking (1-percentages), and another for multiplying the reduction up to the respective dates
    Last edited by themachine; 07-05-2010 at 03:19 PM.

  24. #24
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    Please post workbook, not pictures.

    Yoy can drag the formula =$E8:$E99*F8:F99, to the right to get those results, but why bother with an array formula at all for that?

  25. #25
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    The problem is that you're still multiplying by only two arrays independent of position, where as the product one multiplies a variable number of arrays dependent on the position

    I have uploaded the workbook,

    What I'd really like is to remove the products/complement sheets so the main sheet isn't dependent on the other two. It's a very ugly implementation
    Attached Files Attached Files
    Last edited by themachine; 07-05-2010 at 04:07 PM.

  26. #26
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: non constant arrays?

    Rather than using two sheets of helper cells, you could just use a few columns. Changes highlighted, see also defined names.

    DaddyLongLegs might be able to suggest a way to get rid of the helper columns.
    Attached Files Attached Files
    Last edited by shg; 07-05-2010 at 06:18 PM.

  27. #27
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: non constant arrays?

    I can't see any simple way to do that (or really even a complicated way) - I think in this situation you already have the best approach, shg. Even if you could get rid of the helper cells it would be considerably more complex to do so.....
    Audere est facere

  28. #28
    Registered User
    Join Date
    06-27-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2008 MAC
    Posts
    27

    Re: non constant arrays?

    Many thanks for the help.
    Last edited by themachine; 07-06-2010 at 09:03 AM.

+ 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