Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 39 of 39

Thread: Count the number if times a unique number appears in a list

  1. #21
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Actually not quite Scuba, since you asked for the reverse of this effect. With your lastest Workbook sample it only counts the first occurrence with the exception of Cell E2 which for some reason is showing =G4.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  2. #22
    VBAX Regular
    Joined
    Sep 2023
    Posts
    72
    Location
    Quote Originally Posted by Aussiebear View Post
    Actually not quite Scuba, since you asked for the reverse of this effect. With your lastest Workbook sample it only counts the first occurrence with the exception of Cell E2 which for some reason is showing =G4.
    Soz, I had corrected it but uploaded wrong version, correct version attached now
    Attached Files Attached Files

  3. #23
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    I did ask before, which version of Excel do you use?

    For example, if you use Excel 365 you could use the below (first item gets a 1):
    =LET(m,B2:B106,c,C2:C106,r,XLOOKUP(UNIQUE(m&c),m&c,ROW(m)),IF(ISNUMBER(XMATCH(ROW(m),r)),1,0))
    The reverse version would be (last item gets a 1):
    =LET(m,B2:B106,c,C2:C106,r,XLOOKUP(UNIQUE(m&c),m&c,ROW(m),,,-1),IF(ISNUMBER(XMATCH(ROW(m),r)),1,0))
    Last edited by georgiboy; 04-12-2024 at 04:36 AM. Reason: Added reverse option
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  4. #24
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by Scuba View Post
    but I need to total (sum) column C so I can obtain a count of unique container numbers
    So if arnelgp's vba solution is correct, that sum is 44, which you can also get from
    =ROWS(UNIQUE(B2:C106))
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #25
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    @p45cal I make you right, but that depends on their Excel version and if they want to see the result row by row or just the overall sum of unique.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  6. #26
    VBAX Regular
    Joined
    Sep 2023
    Posts
    72
    Location
    Quote Originally Posted by georgiboy View Post
    I did ask before, which version of Excel do you use?

    For example, if you use Excel 365 you could use the below:
    =LET(m,B2:B106,c,C2:C106,r,XLOOKUP(UNIQUE(m&c),m&c,ROW(m)),IF(ISNUMBER(XMATCH(ROW(m),r)),1,0))
    The reverse effect version would be:
    =LET(m,B2:B106,c,C2:C106,r,XLOOKUP(UNIQUE(m&c),m&c,ROW(m),,,-1),IF(ISNUMBER(XMATCH(ROW(m),r)),1,0))
    Apologies, I use Office 365

    I'll try these now, thank you

  7. #27
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by georgiboy View Post
    depends on their Excel version
    Examination of the zip version of their workbook implies it can handle UNIQUE:

    2024-04-12_123752.jpg
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #28
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    Don't forget to look at @p45cal's option in post 24 if you are just wanting an overall sum of unique.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  9. #29
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    Quote Originally Posted by p45cal View Post
    Examination of the zip version of their workbook implies it can handle UNIQUE:
    Appreciate that but I think the TS should inform us, especially when they have already been asked.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  10. #30
    VBAX Regular
    Joined
    Sep 2023
    Posts
    72
    Location
    Quote Originally Posted by georgiboy View Post
    I did ask before, which version of Excel do you use?

    For example, if you use Excel 365 you could use the below (first item gets a 1):
    =LET(m,B2:B106,c,C2:C106,r,XLOOKUP(UNIQUE(m&c),m&c,ROW(m)),IF(ISNUMBER(XMATCH(ROW(m),r)),1,0))
    The reverse version would be (last item gets a 1):
    =LET(m,B2:B106,c,C2:C106,r,XLOOKUP(UNIQUE(m&c),m&c,ROW(m),,,-1),IF(ISNUMBER(XMATCH(ROW(m),r)),1,0))

    This works perfectly for Office 365 and is exactly what I was trying to achieve.

    Thank you everyone who contributed to this, we got there in the end.

    Regards

    Richard

  11. #31
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    If you do want an overall sum then you should look at post 24 from @p45cal as it makes more sense, less intensive on the system.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  12. #32
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by georgiboy View Post
    Appreciate that but I think the TS should inform us, especially when they have already been asked.
    Absolutely!
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  13. #33
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Row2:
    =--(COUNTIFS($B$2:$B$106,B2,$C$2:$C$106,C2)=COUNTIFS($B$2:$B2,B2,$C$2:$C2,C2))
    copy down.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  14. #34
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    That's a nice simple option
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  15. #35
    simplifying your original formula:

    =IF(COUNTIFS(B:B, B2,C:C,C2)>1,IF(COUNTIFS(B:B,B2,C:C,C2)>1,IF(COUNTIFS($B$2:B2, B2, $C$2:C2,C2)=1,1,0),""), 1)
    becomes:

    =IF(COUNTIFS($B2:$B$106, B2,$C2:$C$106,C2)>1,0,1)

  16. #36
    VBAX Regular
    Joined
    Sep 2023
    Posts
    72
    Location
    Quote Originally Posted by arnelgp View Post
    simplifying your original formula:

    =IF(COUNTIFS(B:B, B2,C:C,C2)>1,IF(COUNTIFS(B:B,B2,C:C,C2)>1,IF(COUNTIFS($B$2:B2, B2, $C$2:C2,C2)=1,1,0),""), 1)
    becomes:

    =IF(COUNTIFS($B2:$B$106, B2,$C2:$C$106,C2)>1,0,1)
    That works even sexier

  17. #37
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Sorry to intrude again here but I was testing the results on a table, when I noticed that arnelgp's formula worked but Georgiboy's created a Spill error.
    Attached Files Attached Files
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  18. #38
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Such array formulae don't work well with tables.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  19. #39
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,199
    Location
    Indeed, I feel that it is a design flaw on Microsofts part.

    They push us to use table objects and then don't support their new features with them.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •