+ Reply to Thread
Results 1 to 24 of 24

counting occurences of a country name in a specific column

  1. #1
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    counting occurences of a country name in a specific column

    I have a sheet of variable numbers of rows that will have a variety of countries listed on one column.
    without sorting the sheet i want to have a list of each country (listed on a seperate sheet) with the number of occurences of each.
    i.e.
    Germany 547
    France 325
    UK 679
    I can do it by looping down every row numerous times but as the sheet is a few thousand lines long this is not a good way to do it. can anyone suggest a smarter way?

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: counting occurences of a country name in a specific column

    can you use a pivot table....if your data is setup as shown a pivot table would work very easily....
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: counting occurences of a country name in a specific column

    Use countif function.

  4. #4
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: counting occurences of a country name in a specific column

    Thanks for the reply Ernest but I need to use vba as this will form part of a larger routine

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: counting occurences of a country name in a specific column

    could you attach a clean sample data sheet?

  6. #6
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: counting occurences of a country name in a specific column

    Quote Originally Posted by AB33 View Post
    Use countif function.
    thanks for the reply, how can I use countif when I don't know which country names might be present?

  7. #7
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: counting occurences of a country name in a specific column

    Quote Originally Posted by judgeh59 View Post
    could you attach a clean sample data sheet?
    Thanks Ernest, here is a stripped down sample sheet with the required results on sheet 2
    Attached Files Attached Files

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: counting occurences of a country name in a specific column

    so is the country list static on the results page?...

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: counting occurences of a country name in a specific column

    Please Login or Register  to view this content.
    Last edited by AB33; 06-18-2013 at 05:27 PM.

  10. #10
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    With an pivot table.

    Notice: the results on your sheet don't match with the answer of the pivot table.
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  11. #11
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: counting occurences of a country name in a specific column

    @ oeldere ---his data is not contiguous....I had the same problem then I realized it's not contguous

  12. #12
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    @judgeh59

    Great your pointing the OP on the possibility of Pivot Table.

    It a realy powerfull tool.

    I suggest we let the OP decide if he want's this solution.

  13. #13
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: counting occurences of a country name in a specific column

    @ oeldere - agreed on all point....I'm a very big fan of PT and try to get people to head that direction....even creating them using VBA...Thanks

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: counting occurences of a country name in a specific column

    @ oeldere ,
    Could we use a countif function? I mean a formula.

  15. #15
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    @AB33

    Yes (Yep) you can (of course).

    See the attached file.

    Now I see why the results in the pivot table don't match, with the expected results.

    There are gaps in the data (row 477 is empty).

    Then the table will not expand and the pivot table, won't take this row in the counting of data.
    Attached Files Attached Files

  16. #16
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: counting occurences of a country name in a specific column

    @oeldere --- doesn't that assume that the country list is static....which is why I asked that in #8...if it is, then the countif is a great solution....unless you wanted to add the new country when you update the sample....

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: counting occurences of a country name in a specific column

    @ oeldere ,
    Thank you very much!
    I was wondering if it can be done in one go( One formula). Or is it impossible? It looks like you need to have unique lists on a separate column first and then count them on another separate column.

  18. #18
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    @AB33

    That's the way I have done it.

    Probably it can be done in one formula, but I doubt if it gets easier to understand.

    I copied column B to column J.

    Then I used data => remove duplicated (excel 2007) to get the unique countries.

    After that I used an countif formula.

    But instead of countif I would prefer using pivot table, since that will select the unique countries by it's own.

    If you have questions or comments on this item just ask.

  19. #19
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    @judgeh59

    In this case, I, should have looked better and noticed that there are gaps in the data.

    There are macro's to solve that problem.

    Another option would be to filter on the data and delete the whole rows the filter selected.

    Never the less pivot table will be a good solution for this problem.

  20. #20
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: counting occurences of a country name in a specific column

    @ oeldere ,

    "Probably it can be done in one formula, but I doubt if it gets easier to understand."
    Come on mate!
    Can not get complicated than a code. Please share with us if it could be done in single formula.

  21. #21
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    I will take a look at it, but it will not be today, and probably also not tomorrow.

    I come back to you on this item.

    But as already said I would go for the (easy) pivot table solution.

  22. #22
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: counting occurences of a country name in a specific column

    @AB33

    Please Login or Register  to view this content.
    If it can be done with an formula (and I bet it can) I will also suggest to use built in functionality of excel (excel 2007 => remove duplicates).

    I'm personly not interested in the formula option (in a single formula) if there are better options.

    In this case smaller is not always better (to my opinion).

    So I stick by the given answers (solutions).

  23. #23
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: counting occurences of a country name in a specific column

    @ oeldere ,
    Thanks!

  24. #24
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: counting occurences of a country name in a specific column

    Sorry for not replying earlier guys, I have been offline for a few days. I very much appreciate your responses and comments, reading through this thread has enabled me to increase my understanding already. Pivot tables are something I don't really use much and consequently don't have much knowledge of - I must learn more
    The code supplied by AB33 in #9 works perfectly - thank you so much. I don't really understand how it works but will keep on trying.
    Thank you all again for your time and responses.
    Last edited by tryer; 06-21-2013 at 01:36 PM.

+ 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