+ Reply to Thread
Results 1 to 12 of 12

Remove duplicate and Sort

  1. #1
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Remove duplicate and Sort

    I have this code to remove duplicate but I want the result to be sorted. Can anyone help me to revised this code? Thank you.


    Sub RemoveDups(rngDups As Range, Optional rngTarget As Range)
    If rngTarget Is Nothing Then
    rngDups.RemoveDuplicates Columns:=1, Header:=xlNo
    Else
    rngDups.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=rngTarget, Unique:=True
    End If
    End Sub

    Sub Test()
    Call RemoveDups(ActiveSheet.Range("A1:A100"), ActiveSheet.Range("D1"))
    End Sub

  2. #2
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Remove duplicate and Sort

    Hi Gemini528,

    I believe that the macro recording feature will help you out on sorting function, only thing you gonna need to fix in there is the range - I suggest a counta function on certain column to get the proper range - as it seems you can do some coding I believe you´ll handle it, if not just let us know surely one can give you the code here on forum.

    best regards

    Soul

  3. #3
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Remove duplicate and Sort

    Thanks Soul for your prompt reply. I am a newbie and no knowledge on VBA. I also got that code on this forum and it works fine for my need. However, i need it sorted out. Please provide the code. Thank you so much for your help.

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove duplicate and Sort

    Hi..

    Try this..
    See attachment to show it working..

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by apo; 11-21-2013 at 10:37 AM.

  5. #5
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Remove duplicate and Sort

    Thanks APO, It’s working but column “A” has a formula and it has to be converted first to a value before it can be sorted. Also, sorted should start from “D2” (because of the heading) and the macro should be triggered by selecting the sheet. Thank you.

  6. #6
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Remove duplicate and Sort

    Hi Gemini528,

    ah, sorry, thought that the piece you´ve showed us was your work. Well, nvm, I can see Apo is taking care of this one, so I wont steal his credit and let him to finish up this one.

    Have a nice day

    Best regards

    Soul

  7. #7
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove duplicate and Sort

    Hi..

    Try this..

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Remove duplicate and Sort

    Thanks APO. It works fine for my needs for now. Kudos to you...

    BTW. I just added reputation for you.

    Quote Originally Posted by apo View Post
    Hi..

    Try this..

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove duplicate and Sort

    Great.. i am glad you got it working for you..

  10. #10
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Remove duplicate and Sort

    Hi APO,

    Again, I need your help….

    I have a data sheet (sheet1) that I put transaction on it and I need macro to query and list all the transaction made on specific DATE and SKU NO. (sheet2). I am using a formula combination of INDEX and SMALL but it is very slow to display and search for 20,000 rows. Also, I have to copy it up to the last cell that meets those criteria. Hope you can come up with a macro to run it faster. Again, Thank you.

    SHEET1 (DATA)
    B8 – SKU No.
    C8 – Transaction date.
    D8 – Transaction type
    E8 – Transaction Qty
    F8 – Location
    G8 – Comment

    SHEET2 (RESULT)
    Variables (Transaction Date AND SKU No.)
    A2 – Transaction date (search for transaction date)
    A3 – SKU NO. (search for SKU number)

    Once found, It will display
    A6 – Transaction Type
    B6 – Transaction Qty
    C6 – Location
    D6 – Comment

  11. #11
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove duplicate and Sort

    Hi..

    You should start a new thread for this.. as it is not really related to your OP..

    One good reason for this is that many people search for answers on this forum and a relevant thread title helps a lot (your current thread title of "Remove Duplicate and Sort" is a classic example..)

    For a better chance of more people helping.. attach a Workbook so those helping don't have to spend the time re creating your scenario/layout..

  12. #12
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Remove duplicate and Sort

    Thanks APO, I will do that. You're really fast in answering queries...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA code to Copy, remove duplicate and sort
    By GEMINI528 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2013, 04:12 PM
  2. Remove duplicate IF...
    By bruizer31 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2013, 02:28 PM
  3. excel macro to remove specific columns and rows + remove duplicate
    By garrywelson in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-17-2013, 12:03 PM
  4. Sort - Merge Current Data into blank cells, remove duplicate information
    By cannedyams in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2012, 04:08 PM
  5. Remove duplicate
    By sophiaatwedding in forum Excel General
    Replies: 3
    Last Post: 12-03-2010, 04:50 AM

Tags for this Thread

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