+ Reply to Thread
Results 1 to 13 of 13

VBA to show the count of unique records

  1. #1
    Forum Contributor
    Join Date
    01-08-2012
    Location
    Saudi Arabia, Dammam
    MS-Off Ver
    MS Office LTSC Professional Plus 2021
    Posts
    113

    VBA to show the count of unique records

    Hi
    I have a excel file were i'm using more than 25000 cells and most of the records in it will be duplicate records. In order to get the unique records im using the "Remove duplicate option" but were as to make my summary report im using a formula to count the unique records thus increasing my file size gradually since im going to use it for more records.

    So i wanted to check the possibility to do this using vba to preserve my file size.

    It may not be very clear with my explanation, so i have attached the sample file.

    Thanks
    Attached Files Attached Files
    Last edited by muralidaran; 04-30-2014 at 03:46 PM.
    Thanks & Regards
    Muralidaran.

  2. #2
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: VBA to show the count of unique records

    if you want to count the unique records only then single cell solution is
    copy paste below in C2 then hold control and shift then hit enter to make it array formula
    =SUM(IF(FREQUENCY(MATCH(A2:A75,A2:A75,0),MATCH(A2:A75,A2:A75,0))>=1,1,0))

    change the references as per of your actual data

    if you want to have unique records preserving your actual data then select your data with headers then go to data tab---> Sort and Filter -----> Select Advance.
    select copy to another location (enter the cell where you want your unique data to start) hit Ok.
    Last edited by hemesh; 04-29-2014 at 01:38 PM.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: VBA to show the count of unique records

    Moreover if you want to do it through VBA code, try this code......
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: VBA to show the count of unique records

    @hemesh

    Good one hemesh.

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

    Re: VBA to show the count of unique records

    Hello muralidaran,

    Here is the fastest method to use in VBA for finding unique values. On my computer it would take about 1.3 seconds to scan 25000 rows and return the unique records.

    The attached workbook has the macro below added to it and a button on the worksheet to run it. All previous values in the "Uniques" column are cleared each time the macro is run.

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

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA to show the count of unique records

    @ Leith Ross,

    Hello Leith,

    What an excellent piece of Coding!

    Just to ensure D1 does not lose its heading, I would tweak your Code as follow.

    Please Login or Register  to view this content.
    Kind Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

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

    Re: VBA to show the count of unique records

    Hello Winon,

    Thanks for the tweak. I have included it in the updated macro and workbook.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-08-2012
    Location
    Saudi Arabia, Dammam
    MS-Off Ver
    MS Office LTSC Professional Plus 2021
    Posts
    113

    Re: VBA to show the count of unique records

    Thanks everyone.....
    Mr. Leith Ross your code works fine but my requirement is to show the running count in column B, could you please help me to provide VBA code to show the running total in column B.

    Thanks.
    Last edited by muralidaran; 04-29-2014 at 05:43 PM.

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

    Re: VBA to show the count of unique records

    Hi muralidaran,

    I'll let Leith provide an answer on his fantastic code, but I'd thought I'd also post this as a possible alternative to simply return the count of the unique entries in a range:

    Please Login or Register  to view this content.
    Regards,

    Robert
    Last edited by Trebor76; 04-29-2014 at 08:17 PM.
    ____________________________________________
    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

  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,259

    Re: VBA to show the count of unique records

    Hello muralidaran,

    Here is the updated macro. This will provide you with a running total in column "B". It has been added to the attached workbook.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: VBA to show the count of unique records

    Quote Originally Posted by sktneer View Post
    @hemesh

    Good one hemesh.
    Thanks Sktneer !

  12. #12
    Forum Contributor
    Join Date
    01-08-2012
    Location
    Saudi Arabia, Dammam
    MS-Off Ver
    MS Office LTSC Professional Plus 2021
    Posts
    113

    Re: VBA to show the count of unique records

    Hi Leith Ross
    Thanks for the code, working as required.

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

    Re: VBA to show the count of unique records

    Hello muralidaran,

    You're welcome. My apologies for not understanding what you wanted initially.

+ 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. Count Unique records
    By guido167 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 06-23-2013, 03:08 PM
  2. Calculating Unique records row count
    By plk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-05-2012, 04:26 PM
  3. Excel 2007 : Count Unique Records
    By stevetothink in forum Excel General
    Replies: 2
    Last Post: 11-04-2011, 04:22 PM
  4. Count unique records with criteria
    By vancoservices in forum Excel General
    Replies: 4
    Last Post: 08-24-2010, 09:13 AM
  5. Advanced filter to show unique records
    By ResulG in forum Excel General
    Replies: 3
    Last Post: 12-04-2006, 09:06 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