+ Reply to Thread
Results 1 to 10 of 10

Open, copy and paste worksheets to another workbook

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Open, copy and paste worksheets to another workbook

    Hello,

    Recently, I've been trying to link worksheets from other workbooks to a consolidated workbook. I'm still a beginner at VBA, so this was a little difficult.

    Instead, I'd like to open up workbooks, copy selected sheets, move to a consolidated workbook and then close that workbook. I have to do this for about 100 workbooks, so I'm not too sure how quickly I can do this.

    Is there some way of doing this efficiently.

    Thanks

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open, copy and paste worksheets to another workbook

    Hi, anthony_91,

    maybe have a look at Merge data from all workbooks in a folder or WBs to Sheets for a start.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Open, copy and paste worksheets to another workbook

    Quote Originally Posted by HaHoBe View Post
    Hi, anthony_91,

    maybe have a look at Merge data from all workbooks in a folder or WBs to Sheets for a start.

    Ciao,
    Holger
    Thank you for your reply. I've looked at Part 4 of thie WBs to Sheets. I'd like to modify this code to make it more flexible. I'd like to have the ability to choose the path where I pull workbooks from. I'm assuming I have to modify this code in some way.

    Please Login or Register  to view this content.
    More importantly, I'd like that ability to choose which worksheets to copy by name and into which sheets to paste it into. So for example, if I have a directory on my "C:\Workbooks" and inside that folder I have Workbook_A.xlsm, Workbook_B.xlsm, Workbook_C.xlsm and I want to copy SheetBBB from Workbook_B.xlsm into my consolidated workbook, how can I do that.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open, copy and paste worksheets to another workbook

    Hi, anthony_91,

    regarding the path: ThisWorkbook.Path is the path for the workbook with the code. If you want a different directory please make sure that the last character on a windows system is a backslash.

    Regarding the integration of special sheets from certain workbooks and their destination in the target workbook: should that be the only way to go (not look at any other files in the directory) or is it like take all sheets from all workbooks not specified in the given list?. You could add the workbook name to open, the sheetname to copy and in a thrid column the destination and run a loop on that in an extra worksheet. If all other workbooks are to copied completely you could run a CountIf on the workbook names and decide what to do: 1 says have special orders and 0 just copy everything.

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Open, copy and paste worksheets to another workbook

    Quote Originally Posted by HaHoBe View Post
    Hi, anthony_91,

    regarding the path: ThisWorkbook.Path is the path for the workbook with the code. If you want a different directory please make sure that the last character on a windows system is a backslash.

    Regarding the integration of special sheets from certain workbooks and their destination in the target workbook: should that be the only way to go (not look at any other files in the directory) or is it like take all sheets from all workbooks not specified in the given list?. You could add the workbook name to open, the sheetname to copy and in a thrid column the destination and run a loop on that in an extra worksheet. If all other workbooks are to copied completely you could run a CountIf on the workbook names and decide what to do: 1 says have special orders and 0 just copy everything.

    Ciao,
    Holger
    Hi Holger,

    Thank you for replying. Do I put the path in quotations, e.g.

    Please Login or Register  to view this content.
    So, to go into more detail as to what I'm trying to do. Say I have 5 workbooks in C:\Workbooks

    Workbook_A.xlsm
    Workbook_B.xlsm
    Workbook_C.xlsm
    Workbook_D.xlsm
    Workbook_E.xlsm

    Each of those workbooks has 10 sheets. I only want to copy 2 of those worksheets with a particular sheet name into my consolidated workbook.

    How could I do this with VBA?

    Thanks

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open, copy and paste worksheets to another workbook

    Hi, anthony_91,

    if there is only one person anyswering to the thread you donīt need to quote the whole post.

    You would need to alter the sheetnames to suit but the code passage may look like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Open, copy and paste worksheets to another workbook

    @antony_91

    To me this looks as the same question; if so this is an duplicated post, wich is against the forum rules.

    http://www.excelforum.com/excel-prog...t-opening.html
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  8. #8
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Open, copy and paste worksheets to another workbook

    This code works. Thank you Holger for your help

    Please Login or Register  to view this content.
    Last edited by anthony_91; 08-24-2013 at 03:50 AM.

  9. #9
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Open, copy and paste worksheets to another workbook

    Quote Originally Posted by oeldere View Post
    @antony_91

    To me this looks as the same question; if so this is an duplicated post, wich is against the forum rules.

    http://www.excelforum.com/excel-prog...t-opening.html
    Hi, no it's a different post because I was asking how to link cells without opening the workbooks. I'm now asking how to copy and paste into a consolidated workbook.

    Hope that clarifies that.

  10. #10
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Open, copy and paste worksheets to another workbook

    @anthony_91

    Hi, yes this clarifies that.

    Thanks for the reply.

+ 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. Simple Open Workbook, Copy Sheet, Paste In New Workbook Question
    By alulla in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2013, 02:10 PM
  2. Copy/Paste Range of Data from Multiple Workbooks/Worksheets to Master Workbook/Worksheets
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 08:21 PM
  3. Open workbook, filter values, copy/paste into Active workbook.
    By niceguy21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2013, 12:17 PM
  4. Replies: 2
    Last Post: 09-11-2012, 09:42 AM
  5. Simple task: Open a workbook, copy a range, paste into another workbook
    By fbonetti in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2011, 01:12 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