Find # of Unique Numbers in Large Table

ExcelAtEverything

Active Member
Joined
Jan 30, 2021
Messages
351
Office Version
  1. 2019
Platform
  1. Windows
Inside of a very large 300k row table, I have a column containing 300k cells (C2:C300000) each containing a 10-digit number. I'm wondering if there's a faster and less CPU-intensive method for counting the number of unique numbers in that column. I've tried several methods now, but each seems to slow my computer down more than the last. The most recent formula I tried from the web =SUMPRODUCT(1/COUNTIF(C2:C300000,C2:C300000)) pretty much slowed my computer to a dead stop. Is there a faster/more efficient way to retrieve that number?

1616214392253.png
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
if you only need to check now and then, rather than have the exact number available constantly, you can use the remove duplicates tool in the data menu. that gives you a row count (hence # of uniques). then just undo or dont save.
 
Upvote 0
Thanks Diddi, but unfortunately that won't work. This sheet wil be updated daily each morning with new additional info, and will need that refreshed number each time for accuracy. I also don't wnt to put that on the end user of this sheet to have to do that each time.

Any other ideas?
 
Upvote 0
yes... another possible method is to hide alist of unique values on a spare sheet (hidden?)
initially set up the sheet using the method i suggested above. then in your code, when the user adds a new row, check your list to see if it is new. that will require significantly less grunt than your current method. use last used row method to obtain the count. if you want a smarter method then i can devise faster ones by indexing the list but if this is the right idea then let me know if you need help to implement it
 
Upvote 0
Hmmm. I feel like that option is wrong for this. When the new data is loaded each day (via Power Query), there will be nothing but brand new numbers... none of which could possibly already be in the list. But some in the group of new numbers will be duplicates of themselves. One additional note too... I would like to avoid creating an additional couple hundred thousand rows of data to accomplish this if at all possible. Between all the different tabs in this workbook, it is extremely large already. By years end there will likely be roughly 900k-ish rows of data between all sheets in the WB.

What do you think?
 
Upvote 0
You could try exploring Power Query. This is something in excel which is enabling users to easily process large data sets.

Cheers
 
Upvote 0
so clean out the duplicates once, then on import, clean out new duplicates and then update a counter
 
Upvote 0
I stated that 'm already using PQ, 'I_cant_read'. And every thing I find online about how to do this only allows me to get rid of the duplicates, which I don't want to do because there is info in other columns that is still needed. SO I cannot delete duplicates, I rather just need to count hoiw many of those numbers are unique (because this will provide me with an accurate number of transactions.
 
Upvote 0
When you say 'clean them out", are you saying to delete them? Wouldn't that delete the entire row of info?
 
Upvote 0
Is it possible to use vba?
If so, does this produce the desired result?

VBA Code:
Sub Counting_Uniques()
Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")
    Dim CountRNG As Range, Cell As Range
    Set CountRNG = ActiveWorkbook.Sheets("TEST").Range("C2:C300000") ' Range to count uniques
    For Each Cell In CountRNG
        If Not dict.Exists(Cell.Value) Then
            dict.Add Cell.Value, 0
        End If
    Next
    MsgBox "Unique_values: " & dict.Count
 End Sub
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top