+ Reply to Thread
Results 1 to 17 of 17

Count non unique values

  1. #1
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Count non unique values

    Hi,

    The attached is a subset of a large spreadsheet the sheet has two columns. I want to count which Counties have more than 1 city in the spreadsheet and ideally show this in a message box with the number of times it appears

    So it would show

    Essex Chelmsford 9
    Southend 1


    but would skip Norfolk and go to Kent
    etc etc

    Cities.xlsm

    James

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Count non unique values

    Please Login or Register  to view this content.
    Requires a reference to Microsoft Scripting Runtime.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Thanks for your help

    Is it possible to have the county in the result as well. So it would look something like this

    Essex - Chelmsford (9)
    Essex - Southend (1)

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Count non unique values

    Hello batchjb69,

    The attached workbook will display as requested. The following macro has been added and attached to a button on the worksheet.

    A Message Box can only display a maximum of 1024 characters, including carriage return/ line feed combinations. If you have a large number of counties and cities then creating a UserForm to display them is a better approach.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    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!)

  5. #5
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Cities.xlsm

    Thanks for your help

    OK so Ive put the control in a user form but the result is displayed in a message box still. How to I use the user form to display the result as I believe the result could be greater than 1024 characters

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Count non unique values

    I've added a TextBox to your User Form and output the Text to it.

    Adjust as required ...

    Regards, TMS
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Thanks very much only trouble is the macro doesn't work properly.
    ESSEX should have anther line Southend (1)

    any ideas why?


    ESSEX - Chelmsford (9)
    NORFOLK - Norwich (14)
    KENT - Canterbury (8)
    KENT - Maidstone (2)
    CORNWALL - Truro (9)
    CORNWALL - Plymouth (2)
    DEVON - Exeter (7)

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Count non unique values

    Hello batchjb69,

    I have updated the attached workbook to display a UserForm for you.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Cool cheers for your help only trouble is the macro doesn't quite work properly as per comment in 11:06 of the thread

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Count non unique values

    Hello batchjb69,

    Sorry, I misunderstood your original post.This will return the count of all cities in all counties.
    Attached Files Attached Files

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Count non unique values

    The text box on the user form displayed the same information you had in the MsgBox. I didn't change the logic, only the presentation.

    Regards, TMS

  12. #12
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Cheers but I wanted it to just Display Counties with two or more Cities. So Norfolk would not be displaced in this instance. Is it possible to do this?

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Count non unique values

    Hi batchjb69,

    Try this:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  14. #14
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    City Count.xlsm

    Thanks for all your help this is the best solution the trouble is I need it to ignor citys with one county. SO of the current results Norfolk,Devon & London would not display in the text box



    ESSEX - Chelmsford (9)
    ESSEX - Southend (1)
    NORFOLK - Norwich (14)
    KENT - Canterbury (8)
    KENT - Maidstone (2)
    KENT - Whitstable (1)
    CORNWALL - Truro (9)
    CORNWALL - Plymouth (2)
    DEVON - Exeter (7)
    LONDON - London (1)

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Count non unique values

    You've now changed this requirement a half-dozen times -- duplicates cities, counties and their duplicate cities, all cities in all counties, only counties with two or more duplicated cities, ...

    Before people lose their sense of humor, you might take the time to decide exactly what you want, and then describe it very clearly.

  16. #16
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Apologies what I want is for the macro to return All counties in Column A that have more than 1 city in column B so in the current spread sheet. So in the example Norfolk, Devon & London would not show in the result as they only have 1 city attached to them.

  17. #17
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: Count non unique values

    Apologies what I want is the Macro to display all counties in column A that have more than 1 city in Column B.

    So in the example Norfolk,Devon & London would not display in the text box

  18. #18
    Valued Forum Contributor
    Join Date
    07-29-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003/Excel 2010
    Posts
    534

    Re: Count non unique values

    Based on the previously posted attachments:
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Unique Total Value Count per Unique Lookup Values
    By KnightVision in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-02-2014, 05:03 AM
  2. [SOLVED] Macro to give the count of unique values after comparing the comma separated values
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2014, 12:41 AM
  3. [SOLVED] count unique values based on unique values
    By neetu.aggarwal in forum Excel General
    Replies: 13
    Last Post: 10-23-2012, 04:00 AM
  4. [SOLVED] How To Count Unique Values in COL A Subject for each unique value in COL B ??
    By amirtehrani in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-06-2012, 03:00 AM
  5. Replies: 17
    Last Post: 08-24-2009, 08:58 AM

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