+ Reply to Thread
Results 1 to 22 of 22

Problem using RemoveDuplicates

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Problem using RemoveDuplicates

    Hi,

    I have a simple test worksheet and code. I am trying to delete any rows which are duplicates. I found this cool function called "RemoveDuplicates".

    Here is microsoft link which explains how to use it.......


    anyway, i am trying to use it but for some reason .....nothing happens......no duplicate rows are removed...........any ideas?

    Below is my code an i am also enclosing file.
    Note: For file just refer to sheet1............the last 4 rows of this sheet1 are duplicates and should be removed but they are not.


    code is simple: see below

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    forgot to include link

    HTML Code: 

  3. #3
    Registered User
    Join Date
    03-24-2013
    Location
    Earth
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    81
    hi,to should change exmple code $a$1:$o$9 to your local custom range , 4 rows meaning a1:o4 ?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Problem using RemoveDuplicates

    This works on activesheet

    Sub Macro1()
    '
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    hi all,

    if you look at the link it indicates i should not have to specify the columns IF i plan on using all the columns.....which is what i plan on doing and to be honest the number of cols will change so having to specify Array(1,2,3,....,x) each time would not be possible..........would it?

    i am just lost ........can someone review the link as well.......am i reading it wrong.

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    just to be clear.......so as not to offend anyone.........what i ment by review the link was the "microsoft" link i provided.......in this link it gives an example (which is what i use) where it does not specify "Array(1,2,...,x)".....and this is the type of example i used..........

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Problem using RemoveDuplicates

    You do not have to specify all the columns, unless you want multiple conditions. For e.g. on the attached, you could have used one column 1 or 2. You get the same result.

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    But i want ALL the columns. And in the link from microsoft it says (and gives an example) that if you want all the cols you dont need to specify all of them........as i have done in my code.........but it does not work. i dont get an error or anything it just does nothing. which i was hoping ment that i was doing something wrong that was simple

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Problem using RemoveDuplicates

    When I run my code, it did delete the three rows with red and left one(You had 4 rows at the bottom, now have one)

  10. #10
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    AB33, can you post the code you used? i must be doing something simple that is wrong

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Problem using RemoveDuplicates

    Post #4 work with the attached sheet

  12. #12
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    AB33, in post #4 you specified the columns .......... is this how you got it to work? my code leaves off the columns and according to the microsoft documentation it is supposed to work but does not

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Problem using RemoveDuplicates

    But how does then code know which column you wish to delete?

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Problem using RemoveDuplicates

    If you look at Excel's remove duplicates functions and if you do not select any column, you will get nothing, so this proves you need to select the column.

  15. #15
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    AB33, so microsofts documentation is wrong......big surprise there..........

  16. #16
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    Below is microsoft's documentation:

    "The following code sample removes duplicates with all columns from a range.

    Visual Basic for Applications
    ActiveSheet.Range("A1:C100").RemoveDuplicates "

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Why not just specify the columns?

    I think I know a straightforward way to do it which will work for a varying no of columns.

    Not at a computer right now though, but I'll try and dig it out later.
    If posting code please use code tags, see here.

  18. #18
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    norie, if you know how to do this please let me know.........i would greatly appreciate it.........any idea when you will be able to send out?

    thanks again to all if i have not already said this...........

  19. #19
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    norie,

    i continued searching on the net............i found a forum where you had responded on this very issue.......below is the code you presented in that forum.......

    Please Login or Register  to view this content.

    IT WORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    Things to note: The array starts out at 0 not 1. Since i have 15 columns i have the for-loop go from 0 to 14.


    thanks.......this does seem to work............i will continue validating this ..........

  20. #20
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    norie,

    i continued searching on the net............i found a forum where you had responded on this very issue.......below is the code you presented in that forum.......

    Please Login or Register  to view this content.

    IT WORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    Things to note: The array starts out at 0 not 1. Since i have 15 columns i have the for-loop go from 0 to 14.


    thanks.......this does seem to work............i will continue validating this ..........

  21. #21
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem using RemoveDuplicates

    I was actually thinking of something without a loop.
    Please Login or Register  to view this content.
    I was actully trying that earlier but it wasn't working.

    You just reminded me that the array needed to be 0-indexed, at it works.

  22. #22
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,666

    Re: Problem using RemoveDuplicates

    thanks norie........thanks to all who helped!!!!!!!!!! love this site........keep learning a lot!!!!!!!!!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1