Consulting

Results 1 to 16 of 16

Thread: Group with sum.

  1. #1

    Group with sum.

    Thx XLD for the help on the previous problem.

    I have 3 columns in my my new Sheet: Model, Dealer, Price. I want to group it by Model, then Dealer and the total price per dealer per model.

    How do I accomplish this?

    Thx

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post your workbook example.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    It is Basically a simple long spreadsheet A1 = Model, B1 = Dealer, C1 = price

    Corolla..............X........................$200
    Corolla..............Y........................$300
    Corolla..............X........................$100
    Ford.................Z........................$500
    Ford.................X........................$250
    Ford.................Z........................$200
    VolksWagen.......y........................$150
    VolksWagen.......y........................$350
    VolksWagen.......y........................$350

    The output should be the same but with summing the price
    Corolla..............X........................$300
    Corolla..............Y........................$300
    Ford.................Z........................$700
    Ford.................X........................$250
    Volkswagen........y........................$850


    thx

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I asked for a workbook, to save me the effort of having to build one.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Attached is the data ... thx

  6. #6
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Hi mufasa


    I left 2 ways of doing this. A formula version or a pivottable. I left a attachment below.
    SHAZAM!

  7. #7
    use a DSUM...

  8. #8
    Quote Originally Posted by Shazam
    Hi mufasa


    I left 2 ways of doing this. A formula version or a pivottable. I left a attachment below.
    Thx

    How do I Automate this since there can be 50 records or 500 records?

  9. #9
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Quote Originally Posted by mufasa
    Thx

    How do I Automate this since there can be 50 records or 500 records?

    Then its best to use a pivottable instead if you have that many records. To learn more about pivottables here is a link below.


    http://www.contextures.com/xlPivot01.html#Dynamic
    SHAZAM!

  10. #10
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Mufasa, if you must cross post you must supply the link to the post in the other forum ( you should do this in all forums that you posted the question in) as i have done here:
    http://www.mrexcel.com/forum/showthread.php?t=311576
    Failing to do this will result in your posts getting deleted, it is a common courtesy to show other would be helpers that the solution is being worked on somewhere else so they can collaborate or not waste their time working to the same solution!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  11. #11
    Apologies for the cross post. I am getting desperate from my side. I will delete on Mr Excel

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So does Shaz'z pivottable suggestion do it for you?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    Hi XLD

    The client wants this process automated meaning he clicks a button and data are exported to a CSV file in this format Model Dealer Price. There will be one model for one dealer and total price.

    From a Pivot table point of view it will work but the whole process should be automated.

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this. It uses Shaz's formula solution and automates the CSV part.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15
    HI XLD

    Thanks for the info. How do I dynamically copy the formulas to another worksheet. The reason why I am asking for it is The user obviously clicks on "Create CSV file". This process copies the info from different worksheets in this workbook into the data worksheet with the three columns(Model, Dealer, and Price). Now this can be 50 records or 500 records. This means I can't hard code the formulas because the amount of data will change often.

    Is there a way I can dynamically create fomulas in the result worksheet.

    Thx 4 ur time

  16. #16
    HI XLD

    According to your attachement the formula for the first column is: =INDEX(Data!$A$1:$A$34,SMALL(IF(Data!$B$1:$B$34=B1,IF(MATCH(Data!$A$1:$A$34 &Data!$B$1:$B$34,Data!$A$1:$A$34&Data!$B$1:$B$34,0)=ROW(Data!$B$1:$B$34)-ROW(Data!$A$1)+1,ROW(Data!$B$1:$B$34)-ROW(Data!B$1))),COUNTIF($B$1:B1,B1)))

    Second column: =INDEX(Data!$B$1:$B$34,SMALL(IF(Data!$A$1:$A$34<>"",IF(MATCH(Data!$A$1:$A$3 4&Data!$B$1:$B$34,Data!$A$1:$A$34&Data!$B$1:$B$34,0)=ROW(Data!$B$1:$B$34)-ROW(Data!$A$1)+1,ROW(Data!$B$1:$B$34)-ROW(Data!B$1))),ROWS(B$1:B1)))

    Third Column: =SUMPRODUCT((Data!$A$1:$A$34=A1)*(Data!$B$1:$B$34=B1),Data!$C$1:$C$34)

    These formulas assume that the range is till 34 in the Data Worksheet. Is it possible that I can dynamically generate these formulas and paste the formula only to the result. Reason for this is there is times where there will be 30 records and sometimes 1000 records. This means it is impossible to hard code the formulas. All this should happen in VBA since it runs in the background.

    Thx 4 ur time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •