+ Reply to Thread
Results 1 to 3 of 3

Multiple Condition User Defined Function

Hybrid View

indianagreg Multiple Condition User... 10-04-2010, 03:36 PM
JBeaucaire Re: Multiple Condition User... 10-04-2010, 04:07 PM
Leith Ross Re: Multiple Condition User... 10-04-2010, 04:08 PM
  1. #1
    Registered User
    Join Date
    09-06-2010
    Location
    Indianapolis
    MS-Off Ver
    Excel 2007
    Posts
    2

    Multiple Condition User Defined Function

    I have a fairly static data page (info is cut and pasted quarterly) and a summary page.

    On the summary page, I need data summed by multiple criteria. Each transaction includes the date, salesrep, account, and amount. I need to filter by date, have 3 accounts sum in one place, and 2 in another, and cross reference this by salesrep.

    This is part of a much larger sheet, so a pivot table won't quite work, and I can accomplish this using sumproduct, but I would need to repeat the below equation nearly 9 times in a single cell (3 times for each account) - making it quite long and cumbersome.

    =SUMPRODUCT(--(invoices!$A$6:$A$2000>=Summary!$B$2),--(invoices!$A$6:$A$2000<=Summary!$B$3),--(invoices!$L$6:$L$2000=Summary!A6),--(invoices!$C$6:$C$2000="Fee income : Quarterly Fee"),invoices!$N$6:$N$2000)

    I'm looking for a UDF to complete the task. I got started below with defining some variables and ranges, but I'm not sure where to go next.

    Basically, I'll put this equation next to a cell with the sales rep's name, and it will need to find transactions that are
    • between two dates (the first two conditions in the above sumproduct)
    • have the sales rep's name on them
    • match one of three different accounts
    if the above conditions are met, go ahead and sum the number in the amount column.

    One note - there are a few places on the transaction where a rep's name and amount are listed.

    Thanks in advance.

    Function recurrings(salesrep As String)
    
    Dim dateclosed As Range, account As Range, amount As Range
    Set dateclosed = Sheets("invoices").Range("a6:a2000")
    Set account = Sheets("invoices").Range("c6:c2000")
    Set amount = Sheets("invoices").Range("h6:h6000")

  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: Multiple Condition User Defined Function

    You have Excel 2007, can't you use SUMIFS(). (not SUMIF)
    _________________
    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
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Multiple Condition User Defined Function

    Hello indianagreg,

    Seeing the worksheet is worth a thousand words. Can you post a copy? If you have any information that is personal or confidential, please edit the data accordingly. Please before you post the workbook, do not change the format or layout of the workbook if at all possible. This will ensure you get fast and accurate results.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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