Solved

Delete rows where duplicate values found in column A with Excel VBA

Posted on 2014-02-28
4
7,302 Views
Last Modified: 2014-03-04
There seems to be countless ways on how to delete duplicate values found in a column.  What is the most efficient method in VBA if I know I will have a duplicate value in Col A.  Note I do have several other columns, but none of the columns will have data at the point I do the delete in Col A.
0
Comment
Question by:upobDaPlaya
  • 3
4 Comments
 

Author Comment

by:upobDaPlaya
ID: 39896274
if i did this is this considered sound: ActiveSheet.range("$A$1:$K$410).RemoveDuplicates Columns:=Array(1,2,3,4,5,6,7,8,9,10,11), Header:=xlYes
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39896661
If you just need to test column A, then your statement might be:
    ActiveSheet.Range("$A$1:$K$410").RemoveDuplicates Columns:=1, Header:=xlYes

Open in new window

Note that the above statement is not deleting entire rows. To do that, you might use:
    ActiveSheet.Range("$1:$410").RemoveDuplicates Columns:=1, Header:=xlYes

Open in new window

And if your range truly has data only in A1:A410, you could use:
    ActiveSheet.Range("$A$1:$A$410").RemoveDuplicates Columns:=1, Header:=xlYes

Open in new window


If you have merged cells, a protected worksheet or formulas that are looking at particular cells in the range--please advise.
0
 

Author Comment

by:upobDaPlaya
ID: 39902373
Initially I did not think I had any merged cells, but when I initially posted I failed to mention that I was getting some type of error when using the below code since it thought I had merged cells.  However, I could not find any..  I will try the above...

ActiveSheet.range("$A$1:$K$410).RemoveDuplicates Columns:=Array(1,2,3,4,5,6,7,8,9,10,11), Header:=xlYes
0
 

Author Closing Comment

by:upobDaPlaya
ID: 39905345
Your solution worked, but it is still very puzzling why it thinks my worksheet has merged cells...In fact there is only 1 column.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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