Deleting extra lines of same content

lavppp

New Member
Joined
Apr 17, 2011
Messages
13
Hello to you all (Bonjour from Montreal),

I have a macro which creates a table from an other tab. Once this new table is created I can end up with several lines having the same content.

A1 A2
---------------
cat what ever
dog what ever
rabit what ever
elephant what ever
rabit what ever

In this case I have two lines with the name "rabit".

I would like my macro to delete the second rabit line. The table could end up to have several "cat", "dog", etc. But I want to end up with only one line of "cat", One line of "dog" and so on.

Thank you guys!

Here is my code

Sub Prepare()

Application.ScreenUpdating = False
Sheets("DASH_BOARD_DATA").Select
Range("D2:J13").Select
Selection.ClearContents

p = Sheets("PRIORITY").Cells(1, 1).CurrentRegion.Rows.Count
Set PREP1 = Sheets("DASH_BOARD_DATA").Cells(2, 4).CurrentRegion

x = 2
For i = 2 To p
If Sheets("PRIORITY").Cells(i, 6).Value = 1 _
Or Sheets("PRIORITY").Cells(i, 6).Value = 2 Then
If Sheets("PRIORITY").Cells(i, 17).Value = "X" _
And Sheets("PRIORITY").Cells(i, 18).Value = "" _
And Sheets("PRIORITY").Cells(i, 19).Value = "" _
And Sheets("PRIORITY").Cells(i, 20).Value = "" Then
PREP1.Cells(x, 1) = Sheets("PRIORITY").Cells(i, 7).Value
PREP1.Cells(x, 2) = Sheets("PRIORITY").Cells(i, 8).Value
PREP1.Cells(x, 3) = Sheets("PRIORITY").Cells(i, 21).Value
PREP1.Cells(x, 4) = Sheets("PRIORITY").Cells(i, 22).Value
PREP1.Cells(x, 5) = Sheets("PRIORITY").Cells(i, 25).Value
PREP1.Cells(x, 6) = Sheets("PRIORITY").Cells(i, 26).Value
PREP1.Cells(x, 7) = Sheets("PRIORITY").Cells(i, 29).Value
PREP1.Cells(x, 8) = Sheets("PRIORITY").Cells(i, 6).Value
PREP1.Cells(x, 9) = Sheets("PRIORITY").Cells(i, 13).Value
x = x + 1

End If
End If
Next i
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try

Code:
Range(PREP1.Cells(2,1),PREP1.Cells(x,9)).RemoveDuplicates, Header:=xlNo
 
Upvote 0
No luck. I have put your line after "Next i" and it does not work.

I did a search for the function RemoveDuplicates and I could not find any help in Excel. May be it's because I am using Excel 2003 (I have no choice for the moment to use Excel 2003 due to my job!)

Any other suggestion? :eeek:
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

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