Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Delete rows if they are duplicates

Posted on 2016-11-30
Medium Priority
Last Modified: 2016-11-30

I have data in columns A to columns I, what I am trying to achieve is to run some VBA coding which will remove any duplicates rows so only the one unique line remains, so for example if there are 2, 3, or 5 identical rows of data only 1 line will remain.  I only want to delete the rows if all rows match so column A to column I.

So far I have got to the following

Sub DeleteRows()

With ActiveSheet
Set Rng = Range("A1", Range("B1").End(xlDown))
Rng.RemoveDuplicates Columns:=Array(1,2), Header:=xlYes


Open in new window

But when I implement this code to help me with further columns the result is not what I expected as it looks like its deleted over half my data and data where i know there are no duplicates?

Any idea where i have gone wrong? thanks

Sub DeleteRows()

With ActiveSheet
Set Rng = Range("A1", Range("I1").End(xlDown))
Rng.RemoveDuplicates Columns:=Array(1,9), Header:=xlYes


Open in new window

Question by:Legolas786
LVL 37

Accepted Solution

Kimputer earned 2000 total points
ID: 41907137
If too many are deleted, you probably want this instead:

Sub DeleteRows()

With ActiveSheet
Set Rng = Range("A1", Range("I1").End(xlDown))
Rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9), Header:=xlYes
End With

End Sub

Open in new window

LVL 50

Expert Comment

by:Martin Liss
ID: 41907181
If Kimputer's solution doesn't work for you then please attach your workbook.

Author Closing Comment

ID: 41907191
Thanks, cant believe it was as simple as that

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question