remove duplicates - vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I wrote the code below. It did not work until I typed Columns:=1
Why is that? why I need columns=1 when I said the range is a1:a25. Thank you so much.

Code:
Sub removeduplicate()
    Range("a1:a25").RemoveDuplicates Columns:=1
End Sub
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
With a simple example that you have used, it would seem no to make sense to use columns, but if you can imagine for example that you want to remove duplicates that might be in 2 different columns !!
Code:
Sub removeduplicate()
    Range("a1:C25").RemoveDuplicates Columns:=Array(1, 2)
End Sub
would check to see if there were duplicates in either column (1) OR column (2)
 
Upvote 0
It's because that method has 2 arguments. The column to look at and whether or not the range has header values. The header argument is optional but the column argument is needed.

Your range has only 1 column, so it would make sense that you could leave the column argument out. But, a range could have multiple columns, and the method would need to know which column to focus on when removing duplicates.
 
Upvote 0
Thank you all. How can I know which argument is optional and which is not. I checked the object browser and it does not tell me which on is optional and which one is not. In excel if the argument is bold then it is must but here in Object browser is defined as this

Sub RemoveDuplicates([Columns], [Header As XlYesNoGuess = xlNo])
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top