+ Reply to Thread
Results 1 to 13 of 13

Large SumProduct Array -- original title:Loop Function

  1. #1
    Registered User
    Join Date
    12-05-2007
    Posts
    16

    Large SumProduct Array -- original title:Loop Function

    If someone could provide me a loop function in VBA for these calcultions it would help me very much.

    Cell A1*E1 + B1*F1 + C1*G1
    Cell A2*E1 + B2*F1 + C2*G1
    ......till
    CellA100*E1 + B100*F1 + C100 * G1

    These are the calculations for E1-G1.
    The process must be repeated till E50-G50

    So the second step is:
    Cell A1*E2 + B1*F2 + C1*G2
    Cell A2*E2 + B2*F2 + C2*G2
    ......till
    CellA100*E2 + B100*F2 + C100 * G2

    Thank you in advance, I hope this description is clear as I did not have a VBA code yet.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    VBA is the wrong way to go for this problem.

    It isn't clear what you want to do with this, but some variation of SUMPRODUCT would be faster and easier to maintain than a VB function.

    In the first section are those 100 values, A1*E1+B1*F1+C1*G1 etc. to be considered seperatly or summed together?

    In what cells do you want the results?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-05-2007
    Posts
    16
    As there are so many combinations I thought a VBA function could automatically calculate all the combinations seperately.
    The first 100 combinations have to be calculated seperately and not summed up. The results of the first 100 results can be set into one column.
    In this way there are 5000 combinations in this example.

    Though I have to mention that the real data contains 5151 * 120 combinations, so VBA may be useful?
    Last edited by Divius; 12-19-2007 at 05:10 PM.

  4. #4
    Registered User
    Join Date
    12-05-2007
    Posts
    16
    So it's more a case of getting quick the results. As I have to do it manually it would be a hell of a job

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Have you looked at SUMPRODUCT?

    SUMPRODUCT(A1:C1,E1*G1) is equal to A1*E1 + B1*F1 + C1*G1.

    The table of results can be layed out to take advantage of relative addressing to minimize the typing nessesary. (And the people on this board know some tricks to make layouts behave well.)

    For straight-forward calculations, like this, Excel's innate functions are faster and better than VB. The coding for Excel is closer to machine code than VB and therefore faster.

    If your data is changing infrequently, setting calculation to Automatic Except for Tables will prevent unnessesary re-calculation.

    If you could attach a sample worksheet of the input data and the output data to show where you want these results, we could come up with an easy way for you to get your results.
    Last edited by mikerickson; 12-19-2007 at 07:22 PM.

  6. #6
    Registered User
    Join Date
    12-05-2007
    Posts
    16
    I added the excel file. As you can see there are very much combinations possible. If I have to do this manually with the SUMPRODUCT method this will cost very much time. An automatic alternative would be great. If the results for every 5151 combination are just put into 1 new row there will be 120 rows with results.
    Attached Files Attached Files
    Last edited by Divius; 12-19-2007 at 08:02 PM.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I added columns and a row to label those entries.
    The Name rightSide needs to be added for the formula to work.

    You're right, it is a large project. In order to make it small enough to upload, I, ommited some columns and rows from the result table. Just fill everything to the right and down until you are done.
    Notice that I set calculation to Automatic except Tables.
    Also, the rest of the spreadhseet should be on a different sheet from this data monster.
    Attached Files Attached Files

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Foolish of me. I should share the solution with those who don't want to download a monster file.
    I selected I1 and created a namedRange =OFFSET(!$E$1,COLUMNS(!$E1:E1)-1,0,1,3). Since relative addressing aplies to namedRanges, it is important to select the proper cell when creating a named range.

    Then in I1 I entered =SUMPRODUCT($A1:$A2,rightSide)

    Filling down and right will result in a table of the results.


    (Are these inner products of vectors?)

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    That file is large. The 5151 rows of the group on the left. Those rows are variations of 1-100,1-100,1-100.

    In this file, I eliminated the 5151X3 area and replaced it with a single column of integers A1:100. The three yellow cells are list validated to that column. The column next to the grey area shows the SUMPRODUCT of that row and the entries in the yellow cells.

    I've also changed the title of the thread, since a loop is not the method needed to attack the problem.
    It's still in this forum in case some one has a VB approach.
    Attached Files Attached Files
    Last edited by mikerickson; 12-19-2007 at 11:31 PM.

  10. #10
    Registered User
    Join Date
    12-05-2007
    Posts
    16
    Thank you very much for providing me this quick solution.
    The only thing that misses was the 0 value in the yellow selection menu.
    Could you please tell me how to set the yellow vectors over a wider range including 0.
    As 0 is an important indicator it would be if I could include this one.
    Last edited by Divius; 12-21-2007 at 10:32 AM.

  11. #11
    Registered User
    Join Date
    12-05-2007
    Posts
    16
    Could someone please tell me how I can change the yellow vectors, so the vector includes zero.

  12. #12
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Insert one cell in A1. Put 0 in that cell.
    change the list source for the validation to A1:A101
    Last edited by mikerickson; 12-21-2007 at 11:20 AM.

  13. #13
    Registered User
    Join Date
    12-05-2007
    Posts
    16
    Oke thank you, was quiet easy

+ 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