Formula to calculate unique names

JoakimA

New Member
Joined
Oct 29, 2019
Messages
2
Hi!

I have a large dataset consisting of column A and B. In column A there is an ID that represents a voyage. In column B I have names on the persons that were on the different voyages. I want to calculate how many unique persons that were on the different voyages. How do I do that?

Below I have shown a small table to give an idea of how it looks.

[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Name[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Peter[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Jacob[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Michael[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Jens[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Jens[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Trevor[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Peter[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jacob[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Michael[/TD]
[/TR]
</tbody>[/TABLE]

Hope someone can help.
Thank you!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
There is probably a better way but you can use advanced filter.

Select all rows in the name column, including the heading.

Data---> advanced filter

Action -> copy to another location

List range: this should populate automatically, but it will be B1:Bxxx (assuming NAME column is col B)

Criteria range: copy in the very same as is in list range

Copy to: Select another cell on the same worksheet, say C1

Tick Unique records only then OK & it should do it.
 
Upvote 0
Hi
What about
Code:
Sub test()
    Dim a As Variant, i
    a = Range("a2:a" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 2)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 2) <> 0 Then
                If Not .exists(a(i, 2)) Then
                    .Add a(i, 2), a(i, 1)
                Else
                    .Item(a(i, 2)) = .Item(a(i, 2)) & "," & a(i, 1)
                End If
            End If
        Next
        Cells(1, 1).Resize(, 2).Copy Cells(1, 1).Offset(, 3).Resize(2)
        Cells(1, 1).Offset(1, 3).Resize(.Count, 2) = Application.Transpose(Application.Index(Array(.items, .keys), 0, 0))
    End With
End Sub
 
Upvote 0
Thanks for the answers.

I tried the code in excel, but could not get it to work, but the pivot table worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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