Delete Duplicates from Selection.

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,163
I'm looking for a macro that will remove duplicates from my selection. I will only select cells in 1 col. at a time.
For example, If I select A8:A300 and if the same value is found more than once in the selection, all but one will be deleted.

Thank you for your time and help.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Actually, I found this and it seems to fit my appliction better. However, I can't make it stop deleting my info that is in A1:A6. I only need this to work from A7 down. Any Ideas?

Code:
'Add extra Column, "A" becomes "B"
    Columns(1).EntireColumn.Insert
    
    'Filter out duplicates and copy unique list to "A"
    Range("B7").Select
    Range(Selection, Selection.End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("A7"), Unique:=True

    'Remove extra Column, "B" becomes "A"
    Columns(2).EntireColumn.Delete
 
Upvote 0
Add a section to copy those cells before deleting column B.
Code:
'Add extra Column, "A" becomes "B"
    Columns(1).EntireColumn.Insert
    
    'Filter out duplicates and copy unique list to "A"
    Range("B7").Select
    Range(Selection, Selection.End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("A7"), Unique:=True

    'Remove extra Column, "B" becomes "A"
    Range("B1:B6").Copy Range("A1")
    Columns(2).EntireColumn.Delete
 
Upvote 0
It worked. Except for the embeded picture I have In A1. It stayed in column B and was shrunk. Is there a way around this?
 
Upvote 0
Set the properties of the picture to "Don't move or size with cells".
It should remain on the sheet un-touched and in the original position.
 
Upvote 0
Absolutely perfect. You always have the right answer.
Thank you very much for your help.
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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