+ Reply to Thread
Results 1 to 6 of 6

Subtotal based on filtered list with more than one condition

  1. #1
    Registered User
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    368

    Subtotal based on filtered list with more than one condition

    I have this table,

    A B C
    ----------------------
    buy 50 apple
    buy 130 apple
    buy 20 apple
    sold 50 apple
    sold 25 apple
    buy 20 cherry
    buy 50 pear
    sold 2 cherry
    sold 5 cherry

    and I filter it by choosing a fruit, for exemple "apple". I want to know how I can get the subtotals ("buy" and "sold") for the chosen fruit and put them on two cells.

    the result shoul be like this:

    Total "buy" 200
    Total "sold" 75

    Best Regards
    Elio

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    I'm not sure that you really need Visual Basic for this. I'd use a sumif.

    I took your data and in column D I added the formula:
    =+A2&C2 into each cell

    Then, in columns F, G, & H I created a little summary table:
    Column F has apple, cherry, pear
    in row 1 column G has buy and column H has sold
    in each of the 6 cells in the table, there is this formula:
    =SUMIF($D:$D,G$1&$F2,$B:$B)

    Here are the results:

    buy sold
    apple 200 75
    cherry 20 7
    pear 50 0


    - Pete

  3. #3
    Registered User
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    368
    Your idea is great. I had to make a few changes, but now my problem is gone. Thanks for your help.

    Elio

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Assumptions:

    A15 contains the label "buy"
    A16 contains the label "sold"

    Formula:

    B15, copied to B16:

    =SUMPRODUCT(SUBTOTAL(9,OFFSET($B$2:$B$10,ROW($B$2:$B$10)-MIN(ROW($B$2:$B$10)),0,1)),--($A$2:$A$10=A15))

    Hope this helps!

    Quote Originally Posted by efernandes67
    I have this table,

    A B C
    ----------------------
    buy 50 apple
    buy 130 apple
    buy 20 apple
    sold 50 apple
    sold 25 apple
    buy 20 cherry
    buy 50 pear
    sold 2 cherry
    sold 5 cherry

    and I filter it by choosing a fruit, for exemple "apple". I want to know how I can get the subtotals ("buy" and "sold") for the chosen fruit and put them on two cells.

    the result shoul be like this:

    Total "buy" 200
    Total "sold" 75

    Best Regards
    Elio

  5. #5
    Registered User
    Join Date
    08-15-2012
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Subtotal based on filtered list with more than one condition

    Wow Thanks Domenic

    I have the same problem and your formula works perfectly
    but can you help explain how this formula works?

    Best regards
    pablo

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Subtotal based on filtered list with more than one condition

    Pablo,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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