+ Reply to Thread
Results 1 to 17 of 17

Macro to Transfer Specific Columns from One workbook to another

  1. #1
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Question Macro to Transfer Specific Columns from One workbook to another

    Hi,

    I need to create a macro that transfers 6 different columns in a raw data workbook to another workbook in order to upload the data.

    The problem I am running into is that the cell ranges in the raw data workbook is never going to be the same, therefore I need a code that will only copy the cells with data in them.

    I have tried creating a macro by recording and then editing that string of code but I am not very good with excel.
    Please Login or Register  to view this content.
    Last edited by arlu1201; 05-15-2012 at 10:56 AM. Reason: Please put code tags in future.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to Transfer Specific Columns from One workbook to another

    Hello there,

    Try this,

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    I also get the same error with line

    RD = Windows("Raw Data.xls")

  4. #4
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    * Run-time error '91:

    Object variable or with block variable not set

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Macro to Transfer Specific Columns from One workbook to another

    do you have an example book?
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Macro to Transfer Specific Columns from One workbook to another

    Statements like this:

    LRow = Range("F1").End(xlDown).Row

    Can be broken if you hit a space along the way...you should consider: LRow = SomeSheetVariable.cells(rows.count,6).end(xlup).row

    IN fact this block:

    Please Login or Register  to view this content.
    Can become:

    Please Login or Register  to view this content.


    ---
    May look confusing at first, but saves time when running the code. Also, if you need to copy 6 columns out you can turn the macro in to 6 lines like this (or less if the columns are contiguous). Pretty spiffy.
    Last edited by GeneralDisarray; 05-15-2012 at 03:51 PM. Reason: Sorry! forgot equals sign...was typing direct w/o the editor to catch that

  7. #7
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    Here's two sample books.

    I am fairly lost here.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to Transfer Specific Columns from One workbook to another

    Hey there,

    Sorry I was kind of winging it without the workbooks.

    change the below lines of code

    Please Login or Register  to view this content.
    To look like this
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    This only gave me the top two rows of data.

  10. #10
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to Transfer Specific Columns from One workbook to another

    Okay try changing the below line of code

    Please Login or Register  to view this content.
    to this

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    This returns only 3 lines.

    Thanks for your help everyone, this seems to be quite tricky

  12. #12
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to Transfer Specific Columns from One workbook to another

    How many lines should there be? If you go to te document and press Ctrl End where does it take you?

  13. #13
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    In the example I am trying there is 50 lines, and only the top is being returned. I should note that the top rows in my raw data book have filters so they can be sorted

  14. #14
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to Transfer Specific Columns from One workbook to another

    Then are you trying to copy a filtered selection? That might be why it is only copying the top 3 rows.

  15. #15
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    Yes right now it is only taking the top row of a filtered section. which is the only row I don't want

  16. #16
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to Transfer Specific Columns from One workbook to another

    Alrighty I think this will do the trick, sorry I wasn't aware that you were filtering rows.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    05-15-2012
    Location
    Oshawa, ON
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Macro to Transfer Specific Columns from One workbook to another

    Thats my bad I should have included that. Works perfectly. Thanks a lot!!

+ 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