Solved

Delete rows if they are duplicates

Posted on 2016-11-30
3
11 Views
Last Modified: 2016-11-30
Hi,

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
EndWith

EndSub

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
EndWith

EndSub

Open in new window

0
Comment
Question by:Legolas786
3 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
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

0
 
LVL 45

Expert Comment

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

Author Closing Comment

by:Legolas786
Comment Utility
Thanks, cant believe it was as simple as that
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now