Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New Criteria Prototype 3 18
VBA copy column paste as value 5 21
Excel IF formula 3 19
macro modification Column C 14 26
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

776 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