Solved

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

Posted on 2014-02-28
4
6,931 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
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 Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

920 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

11 Experts available now in Live!

Get 1:1 Help Now