+ Reply to Thread
Results 1 to 4 of 4

conditional user define function

  1. #1
    Registered User
    Join Date
    02-23-2013
    Location
    earth
    MS-Off Ver
    Excel 2010
    Posts
    21

    conditional user define function

    I need a user define function which is similar to excel function named AGGREGATE function (), which allow me to adjust which functions to use.

    The user defines function should look like, UDF (lookup_vector, result_vector, operator, process_1, figure_1, process_2, figure_2)

    The UDF will calculate
    1st step :( process_1, figure_1) then
    2nd step :( process_2, figure_2) then
    3rd step: process 1st step and 2nd step with (operator)

    The conditions for the UDF is below,
    If (process_1) =0, (figure_1) will be any number entry by user
    If (process_1) =1, UDF perform log10 function on (figure_1)
    If (process_1) =2, (figure_1) will be a lookup value, and UDF perform log10 function on the result of the lookup.
    ***Apply the same for (process_2, figure_2)

    If (operator) =0, (figure_1) + (figure_2)
    If (operator) =1, (figure_1) - (figure_2)

    Example,
    Assume $A$1:$B$1 is lookup vector with number 1, 2.
    And $A$2:$B$2 is result vector with number 10, 20.

    UDF ($A$1:$B$1,$A$2:$B$2,0,0,44,0,44)= 44 + 44 =88
    UDF ($A$1:$B$1,$A$2:$B$2,0,1,44,1,44)=log10(44) + log10(44)= 3.286
    UDF ($A$1:$B$1,$A$2:$B2,1,2,1,0,44)=log10(10) - 44= -43

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: conditional user define function

    give this a try, your third example is giving me a different result. Place this code into a standard code module (Insert > Module):

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-23-2013
    Location
    earth
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: conditional user define function

    for the third example ,i had modified the code

    log10(WorksheetFunction.Index(Result_Vector, WorksheetFunction.Match(Figure_1, Lookup_Vector, 0)))

    so all is working,thank you

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: conditional user define function

    I have marked this thread solved for you.
    In the future please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ 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