remove duplicate from top down

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I have this short line of code that removes duplicates rows based on the cell values in column "A"

This works fine but I need to delete from row "A" downwards instead of last row upwards

Code:
b = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A1:Z" & b).RemoveDuplicates Columns:=1, Header:=xlNo

Any idea's please on how to change the code to delete from the top down instead of the bottom up
 

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.
Here is kind of a "brute force" method, but it can all be automated in your code.

First, create a temporary column which you use to add a counter (row 1=1, row 2=2, etc).
Then, have your code sort the data first by this temporary count column in descending order.
Then run the "RemoveDuplicates" command.
Then re-sort the temporary column in ascending order, and delete the temporary column.
 
Last edited:
Upvote 0
If you mean that you want to keep the last value, rather than the first, then just sort the data & then run the code.
 
Upvote 0
As a follow-up to my reply and Fluff's, maybe you already have a column which you can use in sorting (like a date field, or something like that).
If that is the case, then you don't need a temporary column.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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