Consulting

Results 1 to 6 of 6

Thread: Advance filtering unique records

  1. #1

    Advance filtering unique records

    I'm trying to write a code that will filter unique records from Column A & B and pastes the unique records in column Y & Z (See attached). It flags a (run-time error 1004) message without highlighting the error. Can someone assist.

    Thank you kindly


    Sub mac()LRow = Range("A" & Rows.Count).End(xlUp).Row
    
    
    Range("A7:B" & LRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Y7:Z" & LRow), Unique:=True
    End Sub
    Attached Files Attached Files

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Include the header row:

    Sub mac()
        LRow = Range("A" & Rows.Count).End(xlUp).Row
        Range("A6:B" & LRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Y7:Z" & LRow), Unique:=True
    End Sub
    Also, you only need the starting cell for your destination, so

    Sub mac()
        LRow = Range("A" & Rows.Count).End(xlUp).Row
        Range("A6:B" & LRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Y7"), Unique:=True
    End Sub
    should work too.
    Semper in excretia sumus; solum profundum variat.

  3. #3
    When I put the code in my file, I'm still getting the error. Not sure why. See attach
    Attached Files Attached Files

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Sorry, but no error when I ran it.
    VBAX67157.jpg
    Last edited by paulked; 04-16-2020 at 09:37 PM. Reason: Added image
    Semper in excretia sumus; solum profundum variat.

  5. #5
    Ok...I see what happen. I had to clear the results before filtering again. Thank you for helping me resolve this.

  6. #6
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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