Count Total, Unique, array formula?

Pohguan

New Member
Joined
Dec 18, 2019
Messages
8
Office Version
  1. 2010
Platform
  1. Windows
Hi, I have a table below which i need to count the number of unique people who own the same brand of car as Peter. The formula should return 3, 2 from toyota(Paul and David) and 1 from Honda(Ken), it should count David from Nissan as it's a duplicate. Anyone can help to solve this? Thanks
Car
Year
Name
Toyota1999Peter
Toyota2000Paul
Toyota1998David
Mazda1997Michael
Honda1997Peter
Honda1998Ken
Nissan1999Peter
Nissan1998David
Ford1999Peter
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to the MrExcel forum!

Try:

Book1
ABCDEF
1CarYearNameNameCount
2Toyota1999PeterPeter3
3Toyota2000Paul
4Toyota1998David
5Mazda1997Michael
6Honda1997Peter
7Honda1998Ken
8Nissan1999Peter
9Nissan1998David
10Ford1999Peter
Sheet7
Cell Formulas
RangeFormula
F2F2{=SUM(SIGN(FREQUENCY(IF(COUNTIFS(A2:A10,A2:A10,C2:C10,E2),MATCH(C2:C10,C2:C10,0)),ROW(C2:C10)-ROW(C2)+1)))-1}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Thanks, however my actual listing contains over 50,000 rows and about 30 columns, this array formula will take too long to run. is it possible to use vba by any chance if i just need to show autofilter of the 3 "resulted rows"?
 
Upvote 0
Welcome to the MrExcel board!

You could try this user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.

VBA Code:
Function CountSame(data As Range, owner As String) As Long
  Dim d As Object
  Dim a As Variant
  Dim i As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  a = data.Value
  owner = LCase(owner)
  For i = 1 To UBound(a)
    a(i, 3) = LCase(a(i, 3))
    If a(i, 3) = owner Then d(a(i, 1)) = Empty
  Next i
  For i = 1 To UBound(a)
    If a(i, 3) <> owner Then
      If d.exists(a(i, 1)) Then
        If Not d.exists("##" & a(i, 3)) Then
          CountSame = CountSame + 1
          d("##" & a(i, 3)) = Empty
        End If
      End If
    End If
  Next i
End Function

Book1
ABCDEF
1CarYearNameNameCount
2Toyota1999PeterPeter3
3Toyota2000PaulPaul2
4Toyota1998DavidKen1
5Mazda1997Michael
6Honda1997Peter
7Honda1998Ken
8Nissan1999Peter
9Nissan1998David
10Ford1999Peter
Sheet1
Cell Formulas
RangeFormula
F2:F4F2=CountSame(A$1:C$10,E2)
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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