count number of duplicates and then delete duplicates

dougf

New Member
Joined
Mar 15, 2009
Messages
28
I have two columns of data, and I need to create a third column to count the number of times that same line appears in the document (and then remove all but the first copy of that line).

my data looks as follows:

Adam1998 | Jan
Adam1998 | John
Adam1998 | John
Adam1998 | Paul
Adam1998 | Peter
Adam1998 | Peter
Adam1998 | Peter
Adam1999 |John
Adam1999 | Paul


I need this to look as follows:
Adam1998 | Jan | 1
Adam1998 | John | 2
Adam1998 | Paul | 1
Adam1998 | Peter | 3
Adam1999 |John | 1
Adam1999 | Paul | 1

Thank you
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I should add that the data is sorted - so duplicates will appear directly next to each other.
 
Upvote 0
I tried a pivot table, but how would I set this table up? I need a count for the number of that particular occurrence, and I still need to display the information in both of the existing columns.

Why is creating a third column and removing the duplicates not the proper way of reformatting this table?
 
Upvote 0
You need to look at both columns or just one?

Just one:

=COUNTIF($C$1:C1,C1)

Auto filter - Go To - Advanced - Visible cells only...
 
Upvote 0
select your range (make sure your select range includes the field headers).
on the menu bar select Data\Pivot Table
Drop the column 1 and column 2 into the Row fields of the pivot table
Drop column 2 into the Data section of the pivot table. (generally it's set to count here. if not you can always right-click that field and select field settings and change it to Count.

afterwards you can tinker with the pivot table settings to get the right format/look that you want (e.g. if you don't want subtotals, grandtotals etc.)
 
Upvote 0
I need to look at both columns. As in the example, I need to look at both the column A (with Adam1998) and column B (with Jan).

For each row, if the following row's column A and B are identical, I need to delete the following row and increase the count of that row.

One way to implement this is to make column C a column of 1's. If the following row's columnA and columnB are identical to that of the current row, increase the columnC value of the current row and delete the following row.

As with my previous request, it would be most helpful if someone could write this as a VBA script with an iteration starting with row #2 (the first row is a header row), so that I can use some knowledge of iterations from Java in programming future VBA scripts.
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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