+ Reply to Thread
Results 1 to 9 of 9

Copying specific columns

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Copying specific columns

    I have a routine that filters a spreadsheet containing 27 columns of data. After the filter I copy the visible rows to paste into another spreadsheet. I really don't need the whole row, just a few specific columns of data. How do I select just those ranges to copy/paste? My code is below, with the "Copy and paste only the filtered data" part being what I think needs changing. Any help would be appreciated.



    Please Login or Register  to view this content.
    Last edited by jomili; 05-20-2010 at 10:08 AM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Copying specific columns

    I'd suggest deleting the columns you no longer wish to see after the paste. For example:


    Please Login or Register  to view this content.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Copying specific columns

    I'd like to, but unfortunately this is only one copy/paste routine of many. From the source data I run multiple filters, and for each one copy the results to another worksheet. I wind up using most of the columns at one point or other, so can't delete them as I go. For each Filter, I only need 7 or 8 pertinent columns to copy with.

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Copying specific columns

    I'm not quite understanding your issue then. Is there data being pasted over to the new workbook that you don't want there? If so, is there a set criteria for which columns contain data that you want copied?

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Copying specific columns

    For my first autfilter, I autofilter on column M, then I need to copy columns A, F, M, and G

    For my next autofilter, I autofilter on column x, and need to copy A, J, K, L, R and X.

    Next is D, need to copy B, C, F, S, T and I

    And so on, and so forth. There's no real logic to it, except that the data in these columns goes together (IE if I'm pulling Employee Names, I want their phone number and home and office locations with it. If I'm pulling Mail Codes I'd want the employee name, supervisor name, and office location with it. Sometimes I need location code, sometimes I need position function title, sometimes position function code, sometimes job title, sometimes job code, sometimes hire dates, sometimes employee id, etc.)

    So, I need a way to be able to plug into my macro for each step what columns I need to copy. Otherwise I'm copying all of that data every time, and don't need it all, as each autofilter step is for a different select audience.

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Copying specific columns

    I see. What you should use is an Access database. You'll be able to pull only those fields you need from a table with a simple query. If you'd like to post a sample of your worksheet, I'd be happy to put a simple sample database together for you. Much easier and better data structure.

    That being said, lets try to find a solution in excel. The way I see it, you have 1 criteria (the field you are filtering on) and a set of data based on that criteria (the columns to copy to a new sheet). I believe you may need to set up your code to use that criteria as an argument. Something like this:
    Please Login or Register  to view this content.
    I have not tested this, so it may not be perfect. Assign intColCrit as the column number you are filtering based on. Assign arrColtoPaste() elements as each column you want to copy to the new sheet.
    The macro should now paste over everything, then go through and clear all columns you did not want to keep, then delete all empty columns.

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Copying specific columns

    Dave,

    I agree Access would be better, but we're limited to Excel on this one.

    I haven't tried your routine, because the "deleting columns" part concerns me. Here's the gist:

    All of my autofilter copy/paste routines happen in the same sapn of time, from my users hitting a "Go" button in a workbook I've devised. That workbook pulls from 2 other workbooks, the APR and the ESS. I can't delete from either the APR or the ESS because a later autofilter copy/paste will need one of those columns being deleted.

    The data is copied into one single report, with instructions and explanations before and after telling my users what to do with each set of information. In some cases, they'll mail off the data, some they'll take care of themselves, etc. So I can't delete columns in this report either, because I might delete needed data from another report run earlier.

    As I said, I haven't tried your routine yet, so if it's NOT going to be deleting columns let me know. .

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Copying specific columns

    I have removed the delete columns code, so now the results will only show blank columns where you did not want data.

    Please Login or Register  to view this content.
    Can I ask why Access is not allowed?

  9. #9
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Copying specific columns

    Sorry I never replied, got pulled away on other projects. We can't use Access because of turnover. Huh? Here's how it works:

    Employee Bob gets hired on, full of ideas on how to remake the world. He meets the workerbees, and sees them struggling to make Excel do a job that Access is made for. Bob says "I can do that with an Access database!". So, he makes one up, teaches everyone how to use it. There's a big party with cake and cookies, and everybody is thrilled by the new database. Then Bob gets a wild hair and moves to Katmandu to contemplate his navel. Something in the data changes and the database quits running. The workerbees, proficient in Excel but not knowing anything about Access, are stumped. So, they go back to Excel, except they have to refigure out how they were doing it before. A year later, Fred gets hired on, full of ideas on how to remake the world, looks around and says "I can do that with an Access database"....

    That's why we're not allowed to use Access.

+ 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