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
-
Error updating to Win11 0x8024a205
by
bmeacham
33 seconds ago -
default apps
by
chasfinn
7 hours, 11 minutes ago -
Will MS Works 4 work in MS Win 11?
by
MileHighFlyer
5 hours, 32 minutes ago -
Adding links to text in Word 2000
by
sgeneris
16 hours, 40 minutes ago -
FBI warnings are true—fake file converters do push malware
by
Nibbled To Death By Ducks
9 hours, 52 minutes ago -
Classic and Extended Control Panel — no need to say goodbye
by
Deanna McElveen
2 hours, 43 minutes ago -
Things you can do in 2025 that you couldn’t do in 2024
by
Max Stul Oppenheimer
10 hours, 18 minutes ago -
Revisiting Windows 11’s File Explorer
by
Will Fastie
2 minutes ago -
Planning ahead for migration
by
Susan Bradley
2 minutes ago -
Yahoo mail getting ornery
by
Tom in Az
3 hours, 2 minutes ago -
Is Spectrum discontinuing email service?
by
Peobody
1 hour, 17 minutes ago -
Practice what you preach! A cautionary tale.
by
RetiredGeek
2 hours, 16 minutes ago -
Looking for Microsoft Defender Manuals/Tutorial
by
blueboy714
2 hours, 1 minute ago -
Win 11 24H2 Home or Pro?
by
CWBillow
1 day, 10 hours ago -
Bipartisan Effort to Sunset the ‘26 Words That Created the Internet’..
by
Alex5723
2 days, 8 hours ago -
Outlook new and edge do not load
by
cHJARLES a pECKHAM
2 days, 20 hours ago -
Problem using exfat drives for backup
by
Danmc
2 days, 20 hours ago -
I hate that AI is on every computer we have!
by
1bumthumb
1 day, 22 hours ago -
Change Info in the Settings window
by
CWBillow
3 days, 3 hours ago -
Attestation readiness verifier for TPM reliability
by
Alex5723
3 days, 9 hours ago -
Windows Update says that “some settings are managed b your organization”
by
Ed Willers
2 days, 19 hours ago -
Use of Gmail rejected.
by
CBFPD-Chief115
2 days, 20 hours ago -
WuMgr operational questions
by
Tex265
19 hours, 51 minutes ago -
Beijing’s unprecedented half-marathon: Humans vs. humanoids!
by
Alex5723
4 days, 1 hour ago -
New Phishing Campaign Targeted at Mac Users
by
Alex5723
3 days, 1 hour ago -
Backing up Google Calendar
by
CWBillow
4 days, 7 hours ago -
Windows 11 Insider Preview build 27818 released to Canary
by
joep517
4 days, 20 hours ago -
File Naming Conventions (including Folders)
by
Magic66
3 days, 18 hours ago -
Windows 11 Insider Preview Build 26100.3613 (24H2) released to Release Preview
by
joep517
5 days, 3 hours ago -
Microsoft sends emails to Windows 10 users about EOS
by
Alex5723
4 days, 14 hours ago
Recent blog posts
- Classic and Extended Control Panel — no need to say goodbye
- Things you can do in 2025 that you couldn’t do in 2024
- Revisiting Windows 11’s File Explorer
- Planning ahead for migration
- Woody Leonhard (1951–2025)
- What I learned from Woody Leonhard
- Windows Settings today
- Mail Merge magic in Microsoft Word
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.