Solved

Counting Rows with Duplicate Values

Posted on 2012-04-09
12
350 Views
Last Modified: 2012-04-09
In column A I have last name,  and there are multiple rows that contain the same Last name.

I want the count of last names, but only one to count one occurance of the same name.

How would I do this.  I have Excel 2003.
0
Comment
Question by:seamus9909
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 13

Expert Comment

by:Shanan212
ID: 37824283
You could do this via pivot table.

http://www.techonthenet.com/excel/pivottbls/create.php
0
 

Author Comment

by:seamus9909
ID: 37824313
No that counts each occurance of the last name.
0
 
LVL 13

Expert Comment

by:Shanan212
ID: 37824324
=COUNTIF($A:$A,A1)

Paste anywhere and drag it down
Try that - it will display how many times a same name occurs in column A
0
 

Author Comment

by:seamus9909
ID: 37824339
Ok I am not explaining this correctly.


I want to only count the occurance of the last name once.  So:


Dean
Dean
Dean
Dean
Dean
Smith
Smith



Count of Dean = 1
Count of Smith = 1
0
 
LVL 11

Expert Comment

by:ScriptAddict
ID: 37824342
I would also check out the match function.  It sounds like it would do what you need.

=MATCH(A1,A:A,FALSE)
0
 
LVL 11

Expert Comment

by:ScriptAddict
ID: 37824354
Hmmm perhaps you are trying to get a list/count of unique last names?  Because the count will always equal one based on your recent post.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:seamus9909
ID: 37824364
Yes I want to get a list of all the names found.
0
 
LVL 11

Expert Comment

by:ScriptAddict
ID: 37824414
Ok.... use advanced filter.

1)Select column containing last names
2) hold alt and press dfa
3)Click the checkbox for unique records only
4)Look in bottom left hand corner of the Excel window.  You should some something like 9 of 13 records found.

You should see a list of all unique last names, and the number (9) would tell you how many unique last names exist.

-SA
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 37824457
Display the unique names in column B in a button or macro


Dim colNames As New Collection
Dim RowCount As Long
Dim i As Long

RowCount = ActiveSheet.Range("A:A").End(xlDown).Row - 1

On Error Resume Next
For i = 1 To RowCount
    colNames.Add Range("A" & i).Value, Range("A" & i).Value
Next


For i = 1 To colNames.Count
    Range("B" & i).Value = colNames(i)
Next
0
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 total points
ID: 37824459
You are saying the same thing here


"No that counts each occurance of the last name."

"I want to only count the occurance of the last name once.  So:

Count of Dean = 1
Count of Smith = 1"

The pivot table option would do that
0
 
LVL 11

Expert Comment

by:ScriptAddict
ID: 37824471
You are absolutely right Shanan212.  And I would likely use a Pivot Table, it's just easier to explain how to use the advanced filter.

And I thought the count might be helpful.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37824503
To count a given name, you can use the COUNTIF function:

[C2]Dean
[D2]=IF(COUNTIF(A:A,C2)>0,1,0)

To generate names, you can use an array function.

Let's say you have rows 1-18 in column A that have a header and a list of names.  You can put this in cell D2 and drag down for as many rows as you think might have unique names - in this case, only 17 rows need be copied down.

[D2]=INDEX($A$2:$A$18,MATCH(0,COUNTIF($D$2:D2,$A$2:$A$18)))

Its an array function, so you need CTRL+SHIFT+ENTER to confirm.

with error checking:

[D2]=IF(ISNA(INDEX($A$2:$A$18,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$18)))),"",INDEX($A$2:$A$18,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$18))))

CTRL+SHIFT+ENTER to confirm


See attached.

As suggested, the other alternative is to create a pivot table just to list the unique names, and that would give you the list of the unique names.  That's also in the attached.

Dave
getUniqueList-r1.xls
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now