You are here:

Excel/Macro for deleting duplicate rows

Advertisement


Question
Hi Aidan,

I am in need of a macro which works than the one listed below. I have a database of 72,000+ rows and there are lots of duplicates in the Column E. The macros I wrote is taking more 30 minutes to give me the actual data. Can you please help me out with a macro which runs pretty faster?

The macros I wrote is:

Sub DeleteDups()
    
   Dim x As Long
   Dim LastRow As Long
    
   LastRow = Range("E72700").End(xlUp).row
   For x = LastRow To 1 Step -1
       If Application.WorksheetFunction.CountIf(Range("E2:E" & x), Range("E" & x).Text) > 1 Then
         Range("E" & x).EntireRow.Delete
       End If
   Next x
    
End Sub

Thanks in advance,

Regards,
Gary Taylor

Answer
The macro LOOKS fine, but I'd suggest getting calculation turned to manual before it did it - alternatively, do this without a macro - which tends to be the way I do it - use a formula in a helper column which has a decreasing count if

=countif(e1:$E$72700,e1)

this formula when dragged down will have a reducing count, so that the last entry each time has a one against it - to avoid calculation problems, copy this and paste special, values - and then filter on this column NOT EQUAL to one and delete the results.

A macro COULD be written to automate this if required.  

let me know if you need further help with any of this - more than happy to help further.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Aidan Heritage

Expertise

I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!

Experience

My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

Education/Credentials
I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2016 About.com. All rights reserved.