+ Reply to Thread
Results 1 to 11 of 11

Need some array help

  1. #1
    Registered User
    Join Date
    08-23-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    9

    Need some array help

    So I have Array A and Array B; I have to multiply them together (Array C), sum Array C, and then divide Array C by the sum of Array B

    Example:

    A - B
    0.5 - 150
    0.4 - 200
    0.2 - 400

    So what I usually do is: sum((A2:A4)*(B2:B4))/sum(B2:B4) ctrl+shift+enter, but I want to create a function that does this for me where I could just enter the range A2:B4 as the input argument

    Any help? I have been trying but Excel is being a pain with the summing of Array B
    Last edited by akeiser88; 08-24-2011 at 02:07 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need some array help

    Try using SUMPRODUCT like this

    =SUMPRODUCT(A2:A4,B2:B4)/SUM(B2:B4)

    ...it's more difficult if you only want to refer to the range A2:B4.....you can do that with INDEX

    =SUMPRODUCT(INDEX(A2:B4,0,1),INDEX(A2:B4,0,2))/SUM(INDEX(A2:B4,0,2))
    Last edited by daddylonglegs; 08-23-2011 at 11:26 AM.
    Audere est facere

  3. #3
    Registered User
    Join Date
    08-23-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Need some array help

    Thanks for the quick response...but i want to create a function for it so that I can just highlight the range once...with the formula i use above (sum((A2:A4)*(B2:B4))/sum(B2:B4)) or your formula I have to highlight all 3 ranges separately...i want to just highlight one range (the 2 columns together) and have it do the calculation

    i use this formula a lot for work, and i dont feel like highlighting long columns of data 3 separate times

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need some array help

    If you want a single range then I think you need to do it using the second formula I suggested....you still have to refer to it three times in the formula, though. or are you looking for a VBA solution?

  5. #5
    Registered User
    Join Date
    08-23-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Need some array help

    oh sorry sorry yeah i meant i wanted to create a function in VBA that accomplished this...so basically i could go into a cell and type: =xyz(A2:B4) and i will get my answer

  6. #6
    Registered User
    Join Date
    08-23-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Need some array help

    i have this so far

    Please Login or Register  to view this content.
    but anytime the bottom is greater than 32790 I get #VALUE!, but it works when it is below that value, i dont get it
    Last edited by akeiser88; 08-23-2011 at 11:55 AM.

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Need some array help

    akeiser88,

    In your code, instead of dimming as Integer, dim as Double, that should take care of it.

    ~tigeravatar

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Need some array help

    Dimming as Long instead of Integer is an alternative to dimming as Double. Either way should correct the issue

  9. #9
    Registered User
    Join Date
    08-23-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Need some array help

    ahh yes it worked, I dimmed it as a double, thank you very very much tigeravatar

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,262

    Re: Need some array help

    You could also do something like:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Need some array help

    or
    Please Login or Register  to view this content.



+ 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