+ Reply to Thread
Results 1 to 20 of 20

Filter, copy specific columns, and paste to another sheet.

  1. #1
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Filter, copy specific columns, and paste to another sheet.

    Good morning,
    Yeah it is 1:33 am where I am.
    I'd like to filter a column and paste only 2 columns to another sheet in the first available row.
    I found a code that was posted by Tom Ogilvy and made a few adjustments:
    Please Login or Register  to view this content.
    I can't seem to adjust it to copy 2 columns.
    I've attached a file.
    Can anyone help?
    Regards,
    Xrull
    Attached Files Attached Files
    Last edited by Xrull; 09-29-2009 at 06:34 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    If the 2 columns are contiguous try altering the Resize from

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    EDIT: just looked at the attachment and note the above will not always be appropriate (as is)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    Questions...

    Are you only ever copying 2 columns or is the intention such that you will modify headers on Sheet2 row 1 and you intend to copy data from Sheet1 to match the headers listed on Sheet2 (B1 onwards) ?

  4. #4
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    DonkeyOte,
    My actual spreadsheet has 54 columns. I want to filter by column 54 (BB) and copy only columns copy columns B, T,AD, AO:AQ.
    Thanks,
    Xrull

  5. #5
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    Bump I'm still working on it.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    Slipped under the radar... sorry... perhaps:

    Please Login or Register  to view this content.
    Alter sheets & ranges to suit requirements.

  7. #7
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    It is me again.
    DonkeyOte, I ran the code, but I keep getting the message:
    PHP Code: 
    Run-time error '91':
    Object Variable or With block variable not set
    The error is on this line

    Please Login or Register  to view this content.
    Thanks again,
    Xrull
    Last edited by Xrull; 09-28-2009 at 06:42 AM.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    Can you create a file which replicates your setup and has the code in place (which generates the error) ?

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    Here is a working example:
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    Donkeyote,
    I got the code to work; it was failing because I didn't filter all the columns, but how do I filter Column 54 by a criteria column say CO31, and paste the data to the first empty row one Sheet 1 of your example?
    Thanks,
    Xrull

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    Assuming CO31 is not hidden as a result of the filtering process perhaps add:

    Please Login or Register  to view this content.
    on the line preceding the IF block.

  12. #12
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    DonkeyOte,
    I tried adding the line, but I get this message:
    PHP Code: 
    Run-time error '1004':
    Method 'Range of object' _'Worksheet' failed 
    when I try it on your worksheet
    Please Login or Register  to view this content.
    Thanks again,
    Xrull

  13. #13
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    Is "b" a named range ?

    Yes: Then I presume it's on a sheet away from that being filtered in which case remove the preceding period (.) from before the Range reference

    No: Which cell contains the filter criteria ? Or is "b" meant to be a constant - ie filter "b" ?

  14. #14
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    DonkeyOte,
    I'm trying to filter column 54 by the letter b on the worksheet you sent me.
    Thanks,
    Xrull

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    "b" is not a Range object so remove that highlighted in red:

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    DonkeyOte,
    I'm still getting an error message saying Run-time error '91':
    Object Variable or With block vairable not set
    Please Login or Register  to view this content.
    Thanks,
    Xrull

  17. #17
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    I confess I'm getting confused - before you wanted to use a variable whereas now you're using a constant... why not post a file that reflects your real setup and outline what you want to do exactly.... do you really intend to use a constant in the filter ?
    As is this thread is getting a little out of hand for what should in reality be a pretty straightforward exercise.

  18. #18
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    DonkeyOte,
    I apologize for not stating clearly what I want the macro to do. I've uploaded a file. I would like the macro, to filter Sheet3 column BB with the criteria "KialmeFt" and copy the columns B:B,T:T,AD:AD, and AO:AQ, then release the filter.
    Thanks you,
    Xrull
    Attached Files Attached Files

  19. #19
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Filter, copy specific columns, and paste to another sheet.

    This worked in your file (for me) without incident... this is exactly the same code as before with exception of reset of filter on BB which was not a requirement previously.

    Please Login or Register  to view this content.
    Re: post 16 and your error, results from:

    Please Login or Register  to view this content.
    In the above you are applying the AutoFilter to a range which has yet to be Set (rngData) - ie the lines should be swapped around in their order per the prior code.
    Last edited by DonkeyOte; 09-29-2009 at 02:31 AM.

  20. #20
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Filter, copy specific columns, and paste to another sheet.

    DonkeyOte,
    The code worked well. Exactly what I needed.
    Thank you very much.
    Xrull

+ 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