Solved

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

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

708 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

13 Experts available now in Live!

Get 1:1 Help Now