+ Reply to Thread
Results 1 to 7 of 7

How to create a custom function that uses an array as input.

  1. #1
    Registered User
    Join Date
    03-19-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Question How to create a custom function that uses an array as input.

    Hi All

    First time poster on this forum so apologies in advance for any errors.

    I'm trying to create a formula that re-weights the originally designated weighting of a value when other assigned weightings in the array have an invalid corresponding value. For my purposes an invalid value will always be blank or negative and the weighting will always equal 100%.

    In English that will mean as follows:

    Weighting Value Re-Weighting
    0.1 1 0.1/(0.1+0.3+...)
    0.2 -1 NULL
    0.3 2 0.3/(0.1+0.3+...)
    ... ... ...

    My current solution is to use the following array formula in each cell of the Re-Weighting column: {=IFERROR((IF(Value1<0,"",Weighting1)/SUM(IF(Value Column<0,"",Weighting Column))),0)}. However since im using this formula in 20 columns for each of the unique values and down approx 1000 rows this has become quite cumbersome.

    What i would like to do is write a custom function that summarises this formula into something like: =REWEIGHT(Value,Weight,ValueArray,Weight Array).

    I've had a play around with some code and searched the forum but i cant find anything that shows how to create a custom array formula (i.e. with the {}) so really any help is appreciated.

    Cheers

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to create a custom function that uses an array as input.

    I don't think so you need to go for UDF.

    Non Array Approach
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    03-19-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to create a custom function that uses an array as input.

    Thanks for your quick response.

    That formula is a lot cleaner than my current one but it still requires the use of extra columns. I want to nest this formula in another one in order to eliminate the ~20 extra columns so i'm trying to figure out a UDF to make it look a bit cleaner.

    This is what ive come up with but it is producing a #VALUE! error

    Please Login or Register  to view this content.
    Thanks

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to create a custom function that uses an array as input.

    Try this...

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-19-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to create a custom function that uses an array as input.

    That formula works well thanks!

    I still seem to be having some problems though. What I want to do next is use the SUMPRODUCT function with the array of Values and the Reweight array.

    I'm using the following formula {=SUMPRODUCT(REWEIGHT(B2:B5,A2:A5,B2:B5,A2:A5),B2:B5)} where Column A are the weightings and column B are the Values. When I break down the formula its the REWEIGHT section that isnt producing a value.

    Thanks very much!
    Last edited by KTWM; 03-21-2013 at 12:24 AM. Reason: Sorry I spoke too soon!

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to create a custom function that uses an array as input.

    Revised Code:-

    Please Login or Register  to view this content.
    Non Array Formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-19-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to create a custom function that uses an array as input.

    That formula doesn't do exactly what i'm looking for, however I have managed to adapt it to achieve the desired result. It isn't a very flexible formula but it does the trick and i can keep the other reweighting formula to work alongside this.

    Please Login or Register  to view this content.
    Thanks again for your help.

+ 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