+ Reply to Thread
Results 1 to 13 of 13

Multiply contents of two arrays then input result into an array

  1. #1
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Multiply contents of two arrays then input result into an array

    For such a simple problem, I am totally perplexed that I cannot find a solution in the internet (and I've been searching for like, ~12 hours for it, and no solution can be found). I'm a first-time user of VBA, so please spare me from the flames.

    I cannot make this work:

    Please Login or Register  to view this content.
    ARRAYTEST function is just... a function (just to test if things work. I am aware of the keystroke to make array results come out using functions). In any case, the code goes like this: A1 to A3 cells are to Array 1, B1 to B3 cells are to Array 2 (ignore Array 3 and 4, just killing doubts from certain things). I wanted it such that Array 5's first data would contain the results of Array 1's first data multiplied to Array 2's first data; Array 5's second data would contain the results of Array 1's second data and Array 2's second data, so on and forth.

    The problem is, whenever I run that code it chucks out an error pointing at this line >>
    Please Login or Register  to view this content.
    Can someone pinpoint what am I doing wrong? Or is there another way of doing it?

    Thanks!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Multiply contents of two arrays then input result into an array

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Multiply contents of two arrays then input result into an array

    Wow, it worked. Thanks a lot for the help. I would like to ask a last question though (I hope you don't mind answering it).

    What just happened? I swear I have never encountered this line yet:
    Please Login or Register  to view this content.
    If possible, could you give me a rundown at the concept behind it, so if I wanted to do the method again, I could do it alone (ie. I don't know what's Redim, LBound, RBound, and 1 To 1)? Again, thanks for helping me. I really appreciated it.
    Last edited by maistral; 12-06-2014 at 11:03 PM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Multiply contents of two arrays then input result into an array

    How about using

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Multiply contents of two arrays then input result into an array

    I found TMS' solution to be simpler for me though.

    I have another problem, however. Given a new array I needed to get the sum product of three columns: the first two columns A1:A4, B1:B4, then the exponential of each column from N1 to Q4 divided by a constant T then store it to each element of the array:

    =sumproduct(A1:A4,B1:B4,exp(N1:N4/T))
    =sumproduct(A1:A4,B1:B4,exp(O1:O4/T))
    =sumproduct(A1:A4,B1:B4,exp(P1:P4/T))
    =sumproduct(A1:A4,B1:B4,exp(Q1:Q4/T))


    This is the code:
    Please Login or Register  to view this content.
    I have to change ArrA(j, 1) to ArrA(j, 2) or something, though I don't know how to. When I do change it manually, the last cell would contain the correct answer. Please help.

    This is the excel spreadsheet if it helps solving my last problem: array exercise.xlsm

  6. #6
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Multiply contents of two arrays then input result into an array

    Bump. Please help

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Multiply contents of two arrays then input result into an array

    Thanks for the rep.

    The original question has been answered. This is a similar but possibly slightly more complex question.

    You would be better to mark this thread as solved and start a new thread. That will get new eyes and more interest. Link back to this thread for background.

    In the short term, you should note that N1:Q4 is a two dimensional range/matrix with 4 x 4 elements. Does that give any clues?

    Regards, TMS

  8. #8
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Multiply contents of two arrays then input result into an array

    Oh, thanks for replying again. I will post a new one as you suggested.

    And amazingly (and sadly), no. I still have no idea how to code it, but I think I know how should it go: in that "For j" loop I would assign different columns or something.

    I still have no idea how to do it though.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Multiply contents of two arrays then input result into an array

    If you want ArrB to be the same saize as ArrA, you need:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    I really don't understand what it is you are trying to do. What is the calculation? What is the expected end result?

    Regards, TMS

  10. #10
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Multiply contents of two arrays then input result into an array

    Hello, thanks for replying again.
    I wanted to do what's in the sheet - as coded it's
    Please Login or Register  to view this content.
    I wanted to implement it in VBA but I am unable to - except when changing ArrA(j, 1) to (j, 2) manually then I would get the result for the second equation. array exercise.xlsm

    Thanks for your help very much - I really appreciate it as I'm totally clueless on what to do, lol.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Multiply contents of two arrays then input result into an array

    Please see the attached example

    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    02-15-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Multiply contents of two arrays then input result into an array

    Yep, this is what I needed. Thanks a lot! :D

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,038

    Re: Multiply contents of two arrays then input result into an array

    You're welcome.




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. [SOLVED] [SOLVED} array of discount multiply to array of amount
    By kirby21 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-03-2014, 11:31 PM
  2. Replies: 4
    Last Post: 01-10-2014, 09:32 AM
  3. [SOLVED] Type Mismatch when trying to multiply arrays within function
    By weekendwarrior in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2012, 03:10 PM
  4. Trick to multiply an array without an array formula
    By kayard in forum Excel General
    Replies: 2
    Last Post: 12-16-2010, 05:07 AM
  5. Multiply non-contigious arrays
    By Rob Gould in forum Excel General
    Replies: 7
    Last Post: 02-28-2005, 09:06 AM

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