VBA How to mark or clear duplicate rows?

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
I have data in columns AB&C

To find duplicate rows I concatenated the 3 cells in each row in 1 cell so now column D is occupied and duplicates of column D's cells denotes the duplicate rows.

I want to keep 1 copy and clear the other duplicates (not delete rows but clear rows)

I have been using =IF(COUNTIF($D$2:$D$1048576,$D2)>1,"x","")

Which states the range to check against, and the single cell; if it is a duplicate show x otherwise be blank.

Unfortunately there is a character limit of 250 to which the above formula then shows VALUE! This is not good enough for my needs.

I need a helper column to mark the duplicates (so i can then "go to special" do shift left to select the whole rows) to right click and clear the relevant rows or a VBA solution that uses a helper column or not to achieve this goal.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Why not just use the built in Remove Duplicates tool found on the Data ribbon ?
 
Upvote 0
How about
Code:
Sub getUniques()
   Dim cl As Range
   Dim v As String
   
   With CreateObject("scripting.dictionary")
      For Each cl In Range("A2", Range("A" & Rows.count).End(xlUp))
         v = Join(Application.Index(cl.Resize(, 3).Value, 1, 0), "|")
         If Not .exists(v) Then
            .Add v, Nothing
         Else
            cl.Resize(, 3).ClearContents
         End If
      Next cl
   End With
End Sub
 
Upvote 0
Hi good question.

The action of deleting rows especially when they are not sequential is an extremely intensive one for excel. On my machine more often than not doing this results in a literal wait time to complete or just freezing and crashing.
I do not always deal with 10s of thousand of rows but it is possible and this vba addition i want would be part of a bigger macro of mine i use.

It is a lot quicker for rows to be cleared and then apply a filter, deselect blanks and copy and paste the data onto a new sheet. I only know this by having to "increase efficiency" of perfectly good macros (that used the command delete rows) that no longer worked quickly (or well; unreliable freezing and crashing) because the datasets i was given got larger; they need to use a different program than excel to be honest.
 
Upvote 0
Thank you Fluff this works, anyone reading I checked fluff's cleared rows against kutools own select first duplicate function, cleared the selected rows and compared the 2 outputs. They were the same.
 
Upvote 0
If you already had code that did what you needed, why did you waste our time asking for something :twisted:
 
Upvote 0
If you already had code that did what you needed, why did you waste our time asking for something :twisted:

Recording Kutools does nothing for the vba editor.

You could do a bunch of fancy tricks while recording and when you stop the recording to check; there is no code.

I hope that's clearer
 
Upvote 0
Fluff

If it means anything, I appreciate reading & learning Dictionaries from the post provided. I'm sure others are benefiting as well.

Thank you sir.
 
Upvote 0

Forum statistics

Threads
1,223,935
Messages
6,175,494
Members
452,649
Latest member
mr_bhavesh

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