+ Reply to Thread
Results 1 to 12 of 12

Count Duplicates In Column

  1. #1
    Forum Contributor
    Join Date
    11-20-2008
    Location
    UK
    MS-Off Ver
    Office 365 For Mac Excel Version 16.88
    Posts
    143

    Count Duplicates In Column

    I'm trying to write a formula that will count the number of instances where there is duplicate data in a cell.

    At the moment I'm using:

    =SUM(--(COUNTIF(B4:B10000,UNIQUE(B4:B10000))>1)/2)

    (I divide the result by 2 as I'm not interested in the total number of duplicate values, I just want to know the number of instances.)

    This works fine when the data is identical like:
    00309
    00309

    (Expected result here would be 1)

    And it also works when the data is (which is what I want it to do)
    00309
    000309

    (Expected result here would be 1)

    However, there are times when the data is something like:
    00309
    00309DoNotUse
    000309 On Hold

    (Ideally I'd also like the result here to be 1)

    The formula misses these.

    It is only the number that I'm interested in finding if it's been duplicated. For example:
    00309
    000309 On Hold
    00310 On Hold
    000311 On Hold

    Should still produce a result of 1

    Is there a way to count the number of duplicates in this way? I would like not only to have a cell that displays the number of duplicates but also to be able to apply conditional formatting using the same parameters.
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    Try this:

    Please Login or Register  to view this content.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor
    Join Date
    11-20-2008
    Location
    UK
    MS-Off Ver
    Office 365 For Mac Excel Version 16.88
    Posts
    143

    Re: Count Duplicates In Column

    Thank you for the reply, unfortunately that doesn't seem to be working for me. I've tried adding that to my actual spreadsheet and the result that formula gives me is 6 whereas it should be 47.

    I've extracted the data from my actual spreadsheet that has all the instances of duplicates into the attached file so you can see what I mean.

    Also, if I try to use this formula in conditional formatting it tells me that "You may not use reference operators (such as unions, intersections, and ranges), array constants, or the LAMBDA function for Conditional Formatting criteria"

    Due to the volume of data it would be really helpful to have the cells highlighted. If it's not possible then I can do it manually.
    Attached Files Attached Files

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    But you changed the formula, so no wonder it's not returning the right result!

    It should be this:

    =LET(n,BYROW(B4:B10000,LAMBDA(r,MAX(IFERROR(--MID(r,1,COLUMN(A:Z)),0)))), u,UNIQUE(n), SUM(--BYROW(u,LAMBDA(r,SUMPRODUCT((n=r)*1)>1))))

    However, that also counts blank rows, so this would be better:

    =LET(n,BYROW(TOCOL(B4:B10000,1),LAMBDA(r,MAX(IFERROR(--MID(r,1,COLUMN(A:Z)),0)))), u,UNIQUE(n), SUM(--BYROW(u,LAMBDA(r,SUMPRODUCT((n=r)*1)>1))))

    Concentrate on this for now. We can deal with the CF issue once we know this is working.
    Attached Files Attached Files
    Last edited by AliGW; 08-15-2024 at 06:50 AM.

  5. #5
    Forum Contributor
    Join Date
    11-20-2008
    Location
    UK
    MS-Off Ver
    Office 365 For Mac Excel Version 16.88
    Posts
    143

    Re: Count Duplicates In Column

    Ahh apologies. When I copied the original formula it created a carriage return when I pasted it and so I manually removed it and must have deleted more than I should. I can't even pretend to understand what the formula is doing so didn't spot the missing - . Anyway this works perfectly now, thank you!

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    OK - does it work in the CF? If not, I can take another look.

    Otherwise, please mark the thread as solved, etc.

    If you want a formula explaining, just ASK.

  7. #7
    Forum Contributor
    Join Date
    11-20-2008
    Location
    UK
    MS-Off Ver
    Office 365 For Mac Excel Version 16.88
    Posts
    143

    Re: Count Duplicates In Column

    Unfortunately not. I still get the message about not using reference operators and LAMBDA (thought that was a dance lol)

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    That's the lambada - and I thought the same thing when I first met this word (not being a mathematician)!

    OK - I'll see what I can do in a short while. Bear with me - I am trying to work through the laundry at the same time!!!

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    How do you feel about a helper column (could be hidden)?

  10. #10
    Forum Contributor
    Join Date
    11-20-2008
    Location
    UK
    MS-Off Ver
    Office 365 For Mac Excel Version 16.88
    Posts
    143

    Re: Count Duplicates In Column

    That could be okay. Ideally it would be hidden just to not confuse people but not the end of the world

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    OK - so I think this is the best way forward.

    In H4:

    =BYROW(TOCOL(B4:B10000,1),LAMBDA(r,MAX(IFERROR(--MID(r,1,COLUMN(A:Z)),0))))

    This column can be wherever you want it to be and can be hidden.

    Then this CF rule for B4:

    =COUNTIF(H$4#,H4)>1

    DON'T change anything other than the column letter if you decide to put the spill helper in another column. Don't remove the $ or the # - if you do, it will not work!

    Applies to: =$B$4:$B$10000
    Attached Files Attached Files

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,029

    Re: Count Duplicates In Column

    In this one, I've put the spill helper onto a new sheet (HiddenSheet):

    =BYROW(TOCOL(Sheet1!B4:B10000,1),LAMBDA(r,MAX(IFERROR(--MID(r,1,COLUMN(A:Z)),0))))

    The CF rule becomes this:

    =COUNTIF(HiddenSheet!A$4#,HiddenSheet!A4)>1
    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. Count duplicates in column
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2021, 03:25 AM
  2. count duplicates in column
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-17-2021, 05:43 AM
  3. [SOLVED] Count a column without duplicates - VBA Only
    By Scoobster_doo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-19-2017, 01:15 PM
  4. [SOLVED] count duplicates in Column E in all worksheets and write their number in Column H
    By wali in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2015, 06:19 AM
  5. [SOLVED] Count Duplicates in column
    By SomeDude0nline in forum Excel General
    Replies: 4
    Last Post: 07-21-2014, 05:49 PM
  6. [SOLVED] Count Duplicates in Column A once as long as there is a number higher than 0 in Column B
    By armbands1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-05-2013, 01:46 AM
  7. [SOLVED] Macro to count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM

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