Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.setup
external usenet poster
 
Posts: 24
Default how to delete duplicate records in a row

Hi. I was browsing the topics in the forum and most of the things I found are
deleting duplicates involve entire rows. My problem is this, I need to delete
duplicate records by row. For instance, in my example below, I want to
elimate the duplicate "20" under column C so that row 1 would only show 4
records (10, 20, 50 and 30). I'd appreciate any assistance anyonoe can
provide.

A B C D E
10 20 20 50 30
5 5 6 7 8
9 10 11 11 12

Thanks!

Christian

  #2   Report Post  
Posted to microsoft.public.excel.setup
external usenet poster
 
Posts: 35,218
Default how to delete duplicate records in a row

How about a little macro:

Option Explicit
Sub testme01()

Dim iRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long

With Worksheets("sheet1")
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
For iCol = .Cells(iRow, .Columns.Count).End(xlToLeft).Column _
To 2 Step -1
If Application.CountIf(.Cells(iRow, 1).Resize(1, iCol), _
.Cells(iRow, iCol).Value) 1 Then
.Cells(iRow, iCol).Delete Shift:=xlToLeft
End If
Next iCol
Next iRow
End With
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm



Christian wrote:

Hi. I was browsing the topics in the forum and most of the things I found are
deleting duplicates involve entire rows. My problem is this, I need to delete
duplicate records by row. For instance, in my example below, I want to
elimate the duplicate "20" under column C so that row 1 would only show 4
records (10, 20, 50 and 30). I'd appreciate any assistance anyonoe can
provide.

A B C D E
10 20 20 50 30
5 5 6 7 8
9 10 11 11 12

Thanks!

Christian


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.setup
external usenet poster
 
Posts: 24
Default how to delete duplicate records in a row

Hi Dave,
Thanks for this one. It sure made my life easier and simpler.

Again, thanks.
Christian

"Dave Peterson" wrote:

How about a little macro:

Option Explicit
Sub testme01()

Dim iRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long

With Worksheets("sheet1")
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
For iCol = .Cells(iRow, .Columns.Count).End(xlToLeft).Column _
To 2 Step -1
If Application.CountIf(.Cells(iRow, 1).Resize(1, iCol), _
.Cells(iRow, iCol).Value) 1 Then
.Cells(iRow, iCol).Delete Shift:=xlToLeft
End If
Next iCol
Next iRow
End With
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm



Christian wrote:

Hi. I was browsing the topics in the forum and most of the things I found are
deleting duplicates involve entire rows. My problem is this, I need to delete
duplicate records by row. For instance, in my example below, I want to
elimate the duplicate "20" under column C so that row 1 would only show 4
records (10, 20, 50 and 30). I'd appreciate any assistance anyonoe can
provide.

A B C D E
10 20 20 50 30
5 5 6 7 8
9 10 11 11 12

Thanks!

Christian


--

Dave Peterson

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
Deleting duplicate records Keensie Excel Discussion (Misc queries) 1 April 21st 06 08:12 PM
Find duplicate records in Excel 2003 Wayne Excel Discussion (Misc queries) 1 March 29th 06 12:47 AM
How do I delete duplicate records from an entire Excel workbook? Steven B. Excel Discussion (Misc queries) 0 December 6th 05 10:32 AM
How do I find duplicate rows in a list in Excel, and not delete it Matthew in FL Excel Discussion (Misc queries) 2 June 15th 05 09:11 PM
How to delete duplicate records when I merge two lists (deleting . rinks Excel Worksheet Functions 10 December 11th 04 01:03 AM


All times are GMT +1. The time now is 02:16 AM.

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

About Us

"It's about Microsoft Excel"