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.

IDName
1Peter
1Jacob
1Michael
1Jens
2Jens
2Trevor
2Peter
3Jacob
3Michael

<tbody>
</tbody>

Hope someone can help.
Thank you!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,215,472
Messages
6,125,003
Members
449,203
Latest member
Daymo66

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