Consulting

Results 1 to 3 of 3

Thread: Flexible copy-to range

  1. #1

    Flexible copy-to range

    In the following code, unique records are copied to a new range starting with cell A56. How can I amend this so that it just starts copying 3 rows down from the last populated row wherever that might be?

    Sub filter_unique_records() 
    Sheets("Pivot Data").Select
    Range("A3:I49").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
    "A56"), Unique:=True
    End Sub

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Try this.

    Sub filter_unique_records()
    Dim ws As Worksheet Dim LastRow As Long Set ws = Sheets("Pivot Data") LastRow = ws.Range("A65536").End(xlUp).Row ws.Range("A3:I49").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ws.Range("A" & (LastRow + 3)), Unique:=True End Sub

  3. #3
    works perfectly. Thanks!!

Posting Permissions

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