Count number of unique codes in a column

rob51852

Board Regular
Joined
Jun 27, 2016
Messages
163
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have a spreadsheet which contains a list of 70,000 numeric codes in column B. Some of the codes are duplicated multiple times.

Is there a formula that will count the number of unique codes?

Thanks
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

James006

Well-known Member
Joined
Apr 4, 2009
Messages
3,680
Hi,

You can use following formula

=SUMPRODUCT(1/COUNTIF(yourRange,yourRange))

Hope this will help
 

rob51852

Board Regular
Joined
Jun 27, 2016
Messages
163
Office Version
  1. 2016
Platform
  1. Windows
Hi,

You can use following formula

=SUMPRODUCT(1/COUNTIF(yourRange,yourRange))

Hope this will help

Hi James,

Thanks. The formula just returns a 0... Have I transposed it wrong:

=SUMPRODUCT(1/COUNTIF(D2:D61932,D2:D61932))
 

James006

Well-known Member
Joined
Apr 4, 2009
Messages
3,680
Hi,

Apparently 70'000 records is too much for Excel to swallow ...

Would suggest to Insert a Pivot Table ... much safer ...
 

rob51852

Board Regular
Joined
Jun 27, 2016
Messages
163
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

Hi,

Apparently 70'000 records is too much for Excel to swallow ...

Would suggest to Insert a Pivot Table ... much safer ...

Thanks. Just came back to my PC and it's done it: 2152

Thanks again
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,121
Assuming you have headers in row 1, try this macro:
Code:
Sub CountUniques()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rowCount As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range("B1:B" & LastRow).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("B1:B" & LastRow), Unique:=True
    rowCount = [subtotal(103,B:B)] - 1
    MsgBox ("There are " & rowCount & " unique values.")
    Range("B1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,738
Messages
5,597,829
Members
414,180
Latest member
Sir Khaya

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
Top