View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Deleting duplicates within rows

You could use a macro:

Option Explicit
Sub testme()
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCol As Long
Dim LastCol As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 1 'no headers???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
LastCol = .Cells(iRow, .Columns.Count).End(xlToLeft).Column
For iCol = LastCol To 2 Step -1
If Application.CountIf(.Rows(iRow), _
.Cells(iRow, iCol).Value) 1 Then
'more than one found, delete this one
.Cells(iRow, iCol).Delete Shift:=xlToLeft
End If
Next iCol
Next iRow
End With
End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

ComeOn12 wrote:

I need to delete duplicate cells that occur within a row, and return only the
unique cells. There are 4 colums and almost 7000 rows.

Example of rows:
123 Main St Ste 789 123 Main St
987 Elm St 1st Floor 1st Floor Room A
311 West St 311 West St

Need to return across multiple cells:
123 Main St Ste 789
987 Elm St 1st Floor Room A
311 West St

THANKS!


--

Dave Peterson