duplicated cells in a column

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
Can I just delete duplicated cells in a column BUT without shifting other cells to the top? I used Data-->remove duplicate but that would remove duplicated cells and move everything up.
Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi
Can I just delete duplicated cells in a column BUT without shifting other cells to the top? I used Data-->remove duplicate but that would remove duplicated cells and move everything up.
Thanks

You can achieve this only with vba. Another solution is make a helper column. For example you have your data in column A. In B2 write:
=IF(MATCH($A2,$A$1:$A1,0)>0,"",$A2)

Then pull down. After copy Colum B and paste as only values to column A.
 
Last edited by a moderator:
Upvote 0
@ Flashbond
Your formula needs a tweak as it returns blank or #N/A

@ lezawang
Another manual way
1. Select the column by clicking its heading label
2. Home -> Conditional Formatting -> Highlight Cells Rules -> Duplicate Values -> OK
3. With the column still selected -> Data -> Filter
4. Note the cell colour of the duplicates (probably the default pink colour) & click the filter drop-down in the top cell and choose -> Filter by Color -> Select the appropriate cell color for the duplicates
5. Select from row 2 to the bottom of the visible cells & hit the Delete key
6. Remove the AutoFilter altogether or from the drop-down choose Select All
 
Upvote 0
@ Flashbond
Your formula needs a tweak as it returns blank or #N/A

@ lezawang
Another manual way
1. Select the column by clicking its heading label
2. Home -> Conditional Formatting -> Highlight Cells Rules -> Duplicate Values -> OK
3. With the column still selected -> Data -> Filter
4. Note the cell colour of the duplicates (probably the default pink colour) & click the filter drop-down in the top cell and choose -> Filter by Color -> Select the appropriate cell color for the duplicates
5. Select from row 2 to the bottom of the visible cells & hit the Delete key
6. Remove the AutoFilter altogether or from the drop-down choose Select All
Yeah, it was not wise to use MATCH. COUNTIF will work:
=IF(COUNTIF($A$1:$A1,$A2)>0,"",$A2)
 
Upvote 0
That is really good. However, when I delete, excel will delete all duplicated values. What I want.. lets say I have 3 cells with value of =10, A1, A5, A20 = 10
I want excel to delete A5, and A20 and keep A10. In your example, it will delete 3 of them A1 A5 and A20

@ Flashbond
Your formula needs a tweak as it returns blank or #N/A

@ lezawang
Another manual way
1. Select the column by clicking its heading label
2. Home -> Conditional Formatting -> Highlight Cells Rules -> Duplicate Values -> OK
3. With the column still selected -> Data -> Filter
4. Note the cell colour of the duplicates (probably the default pink colour) & click the filter drop-down in the top cell and choose -> Filter by Color -> Select the appropriate cell color for the duplicates
5. Select from row 2 to the bottom of the visible cells & hit the Delete key
6. Remove the AutoFilter altogether or from the drop-down choose Select All
 
Upvote 0
In your example, it will delete 3 of them A1 A5 and A20
That is correct and it was because in your original post you said remove duplicates could be used except that it moved all the cells up. Remove duplicates also removes all the duplicated values and you didn't mention that was a problem. ;)

I don't have time right now but if a suitable solution doesn't appear, I will have another look when I can.
 
Upvote 0
How about
Code:
Sub ClearDupes()

   Dim Cl As Range
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Nothing
         Else
            Cl.ClearContents
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
A couple more options. I'v assumed the column is column A & is not populated with formulas or likely the duplication problem could be eliminated by those formulas.

1. Use the manual method suggested by Flashbond in post #2 , but with this modified formula in B2, copied down
=IF(A2="","",IF(COUNTIF($A$1:$A1,$A2)>0,"",$A2))

2. Another macro option.
Code:
Sub Clear_Dupes()
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace(Replace("if(#="""","""",if(match(#,#,0)=row(#)-row(^)+1,#,""""))", "#", .Address), "^", .Cells(1).Address))
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,072
Messages
6,122,966
Members
449,094
Latest member
Anshu121

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