Forum Discussion
Samphire
Oct 10, 2023Copper Contributor
Counting unique values across multiple tabs
Hello. I'm trying to write a formula but am having no luck - help please. I would like to count all unique values (these are client id numbers) in column A across multiple sheets (only counting...
HansVogelaar
Oct 10, 2023MVP
Here is a custom VBA function you can use:
Function CountUnique() As Long
Dim wsh As Worksheet
Dim r As Long
Dim m As Long
Dim c As New Collection
Application.Volatile
On Error Resume Next
For Each wsh In Worksheets
Select Case wsh.Name
Case "Summary"
' Skip this sheet
Case Else
m = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row
For r = 2 To m
If wsh.Range("F" & r).Value <> "" Then
c.Add Item:=1, Key:=CStr(wsh.Range("A" & r).Value)
End If
Next r
End Select
Next wsh
CountUnique = c.Count
End Function
Use like this in a cell:
=CountUnique()
Save the workbook as a macro-enabled workbook and make sure that you allow macros when you open the workbook.