+ Reply to Thread
Results 1 to 6 of 6

VBA: Select filtered rows then copy all but header row

  1. #1
    Registered User
    Join Date
    02-10-2014
    Location
    Maricopa,AZ
    MS-Off Ver
    Excel 2013
    Posts
    4

    VBA: Select filtered rows then copy all but header row

    Warning: Rookie

    I want to filter my dataset, select column B & C to copy, but exclude the header row. I am having a hard time offsetting the selected range. I get a compile error on what I try.

    Here is my code (yes, I know, its a little juvenile and I will clean it up, but I need to see things clearer at first):
    Sub GetBarrelQualifiers()
    '
    ' GetBarrelQualifiers
    '

    '
    Application.ScreenUpdating = False
    Sheets("Entries").Select
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=1
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=1, Criteria1:="NEW TEAM" ' New teams
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=12, Criteria1:="No" ' Not Wrangler
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=13, Criteria1:="No" ' Not Leadline
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=4, Criteria1:="Yes" ' Running in barrels
    Range("B:C").Select

    ' Selection.Offset(1,0)

    Selection.Copy
    Sheets("B-QF").Select
    Cells(2, 1).Select
    ActiveSheet.Paste
    Sheets("Entries").Select
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=1
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=4
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=12
    ActiveSheet.Range("$A$1:$M$17").AutoFilter Field:=13
    Application.ScreenUpdating = True
    Sheets("B-QF").Select
    Cells(1, 1).Select

    End Sub
    It works great, except I'm getting the header row included and pasted on the new sheet.

    I will have a follow up question, if it wanted to be tackled now: how do I append the data, rather than overwrite it? Meaning, I need to find the last populated cell in Sheet "B-QF" column A, then paste in the next cell down.

    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA: Select filtered rows then copy all but header row

    Please use code tags when posting. Maybe:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-10-2014
    Location
    Maricopa,AZ
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: VBA: Select filtered rows then copy all but header row

    I wasn't sure what tags to use, but I'll keep that in mind for my next post(s).

    That worked for me, replacing all the extra copy/paste parts. *THANKS*

    I did change the end of the Range from C17 to C500, because I never know how long that sheet will be. For each use it will populate dynamically. Is there a way to make the end range (C17) more dynamic? I tried using just Range("B2:C") but it erred on that. I don't mind using 500, because we'll not have that many rows in this type of event, but I was trying to be more flexible as I want to reuse my code in later executions.

    Any thoughts on the "Paste as an append" rather than forcing A2 on the paste?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA: Select filtered rows then copy all but header row

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-10-2014
    Location
    Maricopa,AZ
    MS-Off Ver
    Excel 2013
    Posts
    4

    Thumbs up Re: VBA: Select filtered rows then copy all but header row

    This is PERFECT! Thank you so much, John! You're a genius!

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA: Select filtered rows then copy all but header row

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. Select and copy n number of rows from Filtered Table
    By Swindo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-24-2013, 09:30 PM
  2. Need to copy header row in group to all rows below header; stop if blank and repeate
    By jmcaleer10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2013, 11:09 AM
  3. [SOLVED] Copy a specific column data of filtered output without header
    By uvaidya in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-05-2012, 09:21 AM
  4. Replies: 4
    Last Post: 08-16-2012, 06:20 PM
  5. Copy filtered data, not header
    By melbri in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-07-2010, 07:22 PM

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