+ Reply to Thread
Results 1 to 13 of 13

copy range from active worksheet to another workbook

  1. #1
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    copy range from active worksheet to another workbook

    Hi, I want to copy data from a range (A:B) in my activeworksheet to another defined workbook onto a worksheet with the same name. I also want to open the file I am pasting into at the same time. Is there any code around that already does something like this?

    Thanks in advance

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range from active worksheet to another workbook

    To set a variable to the active workbook and activesheet:
    Please Login or Register  to view this content.
    Once that is set, you can refer to that sheet by variable name from anywhere.



    To open a predefined workbook, then set a specific sheet in that workbook as the target, it's pretty similar:
    Please Login or Register  to view this content.



    Now that you have all the variables in place, you can copy directly, then close the workbook you opened, saving it:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: copy range from active worksheet to another workbook

    Thanks - Thats great.

    As an enhancement is it possible to do the same with a workbook, if the sheets in each are named the same?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range from active worksheet to another workbook

    The same as what? Questions like that should be accompanied by clear examples.

  5. #5
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: copy range from active worksheet to another workbook

    Sorry,

    So for example... if I have a workbook with 3 worksheets named Sheet1, Sheet2 and Sheet3. And I want to paste the Range A:B of each of these respective sheets into another destination workbook which has worksheets also named Sheet1, Sheet2 and Sheet3. Would I be able to modify this to do that? So instead of the active worksheet, it would be the active workbook?
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range from active worksheet to another workbook

    Same ideas, but we leave the destination open:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-27-2011 at 10:10 AM. Reason: Corrected macro

  7. #7
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: copy range from active worksheet to another workbook

    I seem to get an error on this line

    Please Login or Register  to view this content.
    Run-time error "424"

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range from active worksheet to another workbook

    My bad:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: copy range from active worksheet to another workbook

    Thanks - the copy is working now. Just the book2 is closing once complete. how can I leave it open?

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range from active worksheet to another workbook

    Take out the line of code that is closing the workbook.

  11. #11
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: copy range from active worksheet to another workbook

    Thanks for your feedback here this is really great help. :-)

    I have a couple of follow up questions on this macro. If I want to change it to copy from "sheet1" in the active workbook and paste in "sheet2" in the destination workbook... is there a simple way to do this?

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy range from active worksheet to another workbook

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-30-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: copy range from active worksheet to another workbook

    thanks!

    if I want to select a range manually (by highlighting; therefore would be different every time) and send those cells to the destination (below) how should I write that?

    Please Login or Register  to view this content.
    (p.s. tell me if this is too many questions)
    Last edited by omarq; 02-03-2011 at 06:37 PM.

+ 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