Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Removing duplicates

Greetings from a Newbie

In my workbook, Sheet1 has a table with several columns and thousands of
rows. I want to delete any rows that contain a duplicate value in column D.
For example, the first time 87E3Y appears in column D - that row is kept.
But, any subsequent times 87E3Y appears in column D, those rows are deleted.

I currently sort all data on Column D, Ascending, then remove the duplicates
by hand. Because I do this every month, I'd like some code to speed this up!

Thank you in advance
Sophie


--
Thanks
Sophie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Removing duplicates

Here is a non-VBA way
Suppose my data looks the first two columns (D and E) below
a 1 1
b 2 1
w 3 1
a 4 2
c 5 1
d 6 1
w 7 2


In F1 I have =COUNTIF($D$1:D1,D1) and I copy this down the column by double
clicking the fill handle
I select all the F entries and use Copy followed by Paste Special- Value to
change formulas to values
Now I select all the data (click on any cell within the data and then use
CTRL+A); use Data | Sort and sort by column F. The data looks like
a 1 1
b 2 1
w 3 1
c 5 1
d 6 1
a 4 2
w 7 2

Delete all the rows below the last value 1 in column F; Delete column F

You might experiment with recording a macro to do all but the last step.
best wishes
--
Bernard Liengme
http://people.stfx.ca/bliengme
Microsoft Excel MVP



"Sophie" wrote in message
...
Greetings from a Newbie

In my workbook, Sheet1 has a table with several columns and thousands of
rows. I want to delete any rows that contain a duplicate value in column
D.
For example, the first time 87E3Y appears in column D - that row is kept.
But, any subsequent times 87E3Y appears in column D, those rows are
deleted.

I currently sort all data on Column D, Ascending, then remove the
duplicates
by hand. Because I do this every month, I'd like some code to speed this
up!

Thank you in advance
Sophie


--
Thanks
Sophie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Removing duplicates

Try the below macro for unsorted data....

Sub DeleteRows_Sophie()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
If WorksheetFunction.CountIf(Range("D1:D" & lngRow - 1), _
Range("D" & lngRow)) 0 Then Rows(lngRow).Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Sophie" wrote:

Greetings from a Newbie

In my workbook, Sheet1 has a table with several columns and thousands of
rows. I want to delete any rows that contain a duplicate value in column D.
For example, the first time 87E3Y appears in column D - that row is kept.
But, any subsequent times 87E3Y appears in column D, those rows are deleted.

I currently sort all data on Column D, Ascending, then remove the duplicates
by hand. Because I do this every month, I'd like some code to speed this up!

Thank you in advance
Sophie


--
Thanks
Sophie

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Removing duplicates

Sophie,

try this

Sub delete_Me()
Dim LastRow As Long, x As Long, y As Long
LastRow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
Dim CopyRange As Range
For x = 1 To LastRow
For y = x + 1 To LastRow
If UCase(Cells(y, 4).Value) = UCase(Cells(x, 4).Value) And _
Cells(x, 4).Value < "" Then
If CopyRange Is Nothing Then
Set CopyRange = Rows(y).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(y).EntireRow)
End If
End If
Next
Next
If Not CopyRange Is Nothing Then
CopyRange.Delete
End If
End Sub


Mike

"Sophie" wrote:

Greetings from a Newbie

In my workbook, Sheet1 has a table with several columns and thousands of
rows. I want to delete any rows that contain a duplicate value in column D.
For example, the first time 87E3Y appears in column D - that row is kept.
But, any subsequent times 87E3Y appears in column D, those rows are deleted.

I currently sort all data on Column D, Ascending, then remove the duplicates
by hand. Because I do this every month, I'd like some code to speed this up!

Thank you in advance
Sophie


--
Thanks
Sophie

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Removing duplicates

One way to speed it up "manually" would be to add a helper column with the
following formula

=COUNTIF($D$1:$D2,$D2)

assuming you are entering this in Row 2. And copy down. Filter all
values int hat column for values greater than 1. Delete all values that are
greater than 1.

I know you're asking for code, but this is another trick that could help.
--
HTH,

Barb Reinhardt



"Sophie" wrote:

Greetings from a Newbie

In my workbook, Sheet1 has a table with several columns and thousands of
rows. I want to delete any rows that contain a duplicate value in column D.
For example, the first time 87E3Y appears in column D - that row is kept.
But, any subsequent times 87E3Y appears in column D, those rows are deleted.

I currently sort all data on Column D, Ascending, then remove the duplicates
by hand. Because I do this every month, I'd like some code to speed this up!

Thank you in advance
Sophie


--
Thanks
Sophie



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Removing duplicates

Hello Sophie,

On my 2007 Excel I click on: Data and Remove Duplicates after marking one or several columns on the Excel sheet.
Simple and works!

best wishes

Gabor Sebo
"Sophie" wrote in message ...
Greetings from a Newbie

In my workbook, Sheet1 has a table with several columns and thousands of
rows. I want to delete any rows that contain a duplicate value in column D.
For example, the first time 87E3Y appears in column D - that row is kept.
But, any subsequent times 87E3Y appears in column D, those rows are deleted.

I currently sort all data on Column D, Ascending, then remove the duplicates
by hand. Because I do this every month, I'd like some code to speed this up!

Thank you in advance
Sophie


--
Thanks
Sophie

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing duplicates in a row mccloud Excel Programming 5 May 26th 09 06:39 PM
Removing Duplicates Help Scott Excel Discussion (Misc queries) 6 May 5th 09 03:58 AM
Removing duplicates Tdp Excel Discussion (Misc queries) 6 November 27th 08 12:33 AM
removing duplicates robhargreaves Excel Discussion (Misc queries) 1 July 24th 05 12:35 AM
removing duplicates marina madeleine Excel Programming 0 September 15th 04 06:39 PM


All times are GMT +1. The time now is 03:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"