+ Reply to Thread
Results 1 to 10 of 10

Sum for each different name

  1. #1
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Sum for each different name

    Hi,

    I am trying to make a sum by VBA for the same name on Column A, such that if a Car Name has exactly the same name, such as to have a for loop to do a sum of the mileage of column B for each consecutive row that yields the same Car Name.

    I attached the Example below, please feel free to have a look. I highlighted the expected answer with green on the right hand side.


    Please Login or Register  to view this content.
    Any help would be greatly appreciated. Thanks1
    Attached Files Attached Files
    Last edited by Gordon85; 12-22-2021 at 10:55 AM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Sum for each different name

    Is there a reason you're using VBA for this rather than just a SUMIF formula?

    This in F4 then copied down will yield the expected results (albeit after you've corrected the mispelling of Volkswagen in column A):
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Could the same car names appear further down the list or would they always be together?
    If they could appear elsewhere in the list do you want to sum them altogether (if so use the formula approach), if you only want to sum them in distinct chuncks then we can help with code for that.

    BSB

  3. #3
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Re: Sum for each different name

    Hi
    Thanks a lot for your quick reply, that's much appreciated.
    I am trying to use VBA rather than the SUMIF formula as in the actual Excel file I got thousands of rows, and that will take time, to manually change the input within each formula. So I'm trying to automatise that by using a FOR loop instead.

    To answer the 2nd question, the cars name will always appear packed together, without discontinuity, so they won't appear further down out of nowhere.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Sum for each different name

    Quote Originally Posted by Gordon85 View Post
    that will take time, to manually change the input within each formula.
    I'm not sure what this means, there's nothing to change in the formula, just plug it into the first cell then drag it down and as it references a cell with the car name it will update each formula automatically. You just need the list of cars and that can easily be done with VBA.

    Even easier, you could just use a Pivot Table to do this for you.

    In the attached I've added the formula and a PT.

    BSB
    Attached Files Attached Files
    Last edited by BadlySpelledBuoy; 12-22-2021 at 11:27 AM.

  5. #5
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Re: Sum for each different name

    That's cool!
    Thanks a lot! Well, yeah the formula works, however, I have to manually change E4 with each string when the Car Name changes, otherwise I'll get the same sum thousand of times until the next Car Name
    Please Login or Register  to view this content.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Sum for each different name

    If you were using a more up to date version of Excel than your profile shows then you could use the =UNIQUE() formula to generate the list of car names then you wouldn't have to change anything.

    I think the Pivot Table is probable the easiest method for this (even though I detest them!)

    BSB

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,214

    Re: Sum for each different name

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  8. #8
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Re: Sum for each different name

    Thanks a lot!
    Solved, REP+

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,214

    Re: Sum for each different name

    ..........................
    Thanks.png

  10. #10
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,381

    Re: Sum for each different name

    @Sintek, in this case you could do this without using .exists

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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