removing duplicates in a row

Lavan

Board Regular
Joined
Dec 15, 2004
Messages
56
Hello All,

Need a macro to delete the duplicate data in a row. My data is like below...

1 Peter Tom Sam Jack Peter Peter
2 Dave Tom Chris Tom Tony
3 Peter Mike Mike Sam
4 Bob Bob

I am looking for a macro to delete all these duplicates in row so that my data should look like below.

1 Peter Tom Sam Jack
2 Dave Tom Chris Tony
3 Peter Mike Sam
4 Bob

Please help.... Thanks in advance,
Lavan
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
Sub lavan()
z = 1
son = [a65536].End(3).Row
Range("A1").Select
For s = 1 To son
e = WorksheetFunction.CountA(Rows(ActiveCell.Row))
a = 0
For y = 1 To e
For i = 1 To e - a
If ActiveCell.Value = ActiveCell.Offset(0, i).Value Then
   ActiveCell.Offset(0, i).ClearContents
   End If
Next i
ActiveCell.Offset(0, 1).Select
If ActiveCell.Value = 0 Then ActiveCell.Delete Shift:=xlToLeft
a = a + 1
Next y
z = z + 1
Range("A" & z).Select
Next s
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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