Remove duplicates in a row

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
whats the best way to remove duplicate data in each column specifying a starting and ending column

beginning sheet remove duplicates starting in row1 column J-P

J K L M N O P
1 cat dog mouse cat
2 bat car ball switch car ball key
3 man boy man woman
4 dog bat ball

output after removal done on row by row

J K L M N O P
1 cat dog mouse
2 bat car ball switch key
3 man boy woman
4 dog bat ball

Thanks
 
OK, think I have it figured out. Try this.

VBA Code:
Sub t5()
Dim c As Range, i As Long
    For Each c In Range("J2", Cells(Rows.Count, 10).End(xlUp))
        For i = Cells(c.Row, Columns.Count).End(xlToLeft).Column To c.Column Step -1
            c.Resize(, i - 9).Replace " ", ""
            If Application.CountIf(c.Resize(, i - 9), Cells(c.Row, i).Value) > 1 Then
                Cells(c.Row, i).Delete xlShiftToLeft
            End If
        Next
    Next
End Sub
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Thanks to the both of you. Dante, yes, yours works well.

as for yours JLGWhiz, I did notice that the code was looking at data starting in row 2. I adjusted it as follows moving it to J1, what else should I have adjusted?
Im trying to learn is why Im asking in order to understand.

Thanks Guys


Here's my adjusted code for your solution


Sub t3()
Dim c As Range, i As Long
For Each c In Range("J1", Cells(Rows.Count, 10).End(xlUp))
For i = Cells(c.Row, Columns.Count).End(xlToLeft).Column To c.Column Step -1
If Application.CountIf(c.Resize(, i), Cells(c.Row, i).Value) > 1 Then
Cells(c.Row, i).Delete xlShiftToLeft
End If
Next
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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