I can use Advanced Filter to copy out the unique items of a column and then count them. However, is there a function that I can use directly to count how many unique items there are? Thanks, Andy.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Counting unique items (2002)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Counting unique items (2002)
- This topic has 9 replies, 8 voices, and was last updated 19 years, 5 months ago.
AuthorTopicWSandrewgibsonsw
AskWoody LoungerOctober 21, 2005 at 11:15 am #425473Viewing 4 reply threadsAuthorReplies-
WSsdckapr
AskWoody LoungerOctober 21, 2005 at 11:20 am #980314Try Chip Pearson’s page Duplicate And Unique Items In Lists
Steve
-
WSmbarron
AskWoody Lounger -
WSGoCush
AskWoody LoungerOctober 22, 2005 at 5:23 am #980441The following code starts with your list of items (Source) then creates a new list of Unique
items (Uniques) — If you dont want the unique list just delete the code line that creates it:The msgbox will then give you the total of unique items.
Sub CreateUniqueList()
””””””””””””””””””””””’
‘Requires a reference to MS Scripting Runtime
‘In the VBA Editor, click on
‘Tools>References>Microsoft Scripting Runtime
”””””””””””””””””””””””Dim Dict As Scripting.Dictionary
Dim i As Integer
Dim oCell As Range
Dim Source As Range
Dim Uniques As Range‘ ‘ Adjust ranges as needed
Set Source = Range(“A:A”)
Set Uniques = Range(“B:B”)Set Dict = New Dictionary
i = 1
With Dict
For Each oCell In Source
If Not .Exists(oCell.Value) Then
If Not oCell.Value = “” Then
.Add Key:=oCell.Value, Item:=i
‘ Optional — Create a unique list
Uniques(i) = oCell.Value
‘ increment the counter
i = i + 1End If
End If
Next oCell
End With
‘Optional Msg
MsgBox “There are ” & i & ” unique items in your list.”Shutdown:
Set Dict = Nothing
Set oCell as Nothing
Set Source as Nothing
Set Uniques as NothingEnd Sub
-
WSmaxflia10
AskWoody Lounger -
WSAladin Akyurek
AskWoody Lounger
-
-
WSmaxbaney
AskWoody LoungerOctober 22, 2005 at 12:22 pm #980474I think the credit for this goes to Hans, however, if it is someone else, I apologize
This function will count unique items in a list:Function CountUniqueValues(InputRange As Range) As Long
Dim cl As Range, UniqueValues As New Collection
Application.Volatile
On Error Resume Next ‘ ignore any errors
For Each cl In InputRange
UniqueValues.Add cl.Value, CStr(cl.Value) ‘ add the unique item
Next cl
On Error GoTo 0
CountUniqueValues = UniqueValues.Count
End FunctionYou would then use CountUniqueValues(a1:a50) or whatever range
Viewing 4 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
1 hour, 24 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
6 hours, 15 minutes ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
7 hours, 24 minutes ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
1 day, 1 hour ago -
50 years and counting
by
Susan Bradley
1 hour, 26 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
8 hours, 22 minutes ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
1 day, 12 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
1 day, 12 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
1 day, 12 hours ago -
OneNote and MS Word 365
by
CWBillow
1 day, 14 hours ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
1 day, 14 hours ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
1 day, 15 hours ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
1 day, 15 hours ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
2 days, 2 hours ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
2 days, 2 hours ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
2 days, 11 hours ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
1 day, 23 hours ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
1 day ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
2 days, 20 hours ago -
Apple backports fixes
by
Susan Bradley
2 days, 3 hours ago -
Win 11 24H2 will not install
by
Michael1950
1 day ago -
Advice to convert MBR to GPT and install Windows 11 Pro on unsupported PC
by
Andy M
29 minutes ago -
Photos from iPhone to Win 10 duplicating/reformatting to .mov
by
J9438
1 day, 9 hours ago -
Thunderbird in trouble. Here comes Thundermail
by
Alex5723
9 hours, 32 minutes ago -
Get back ” Open With” in context menus
by
CWBillow
3 days, 11 hours ago -
Many AMD Ryzen 9800X3D on ASRock have died
by
Alex5723
2 days, 3 hours ago -
simple general stupid question
by
WSaltamirano
3 days, 9 hours ago -
April 2025 Office non-Security updates
by
PKCano
4 days, 2 hours ago -
Microsoft wants to hear from you
by
Will Fastie
1 day, 17 hours ago -
Windows 11 Insider Preview Build 22635.5160 (23H2) released to BETA
by
joep517
4 days, 5 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.