+ Reply to Thread
Results 1 to 20 of 20

Copying cells from multiple workbooks into a new workbook

  1. #1
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Question Copying cells from multiple workbooks into a new workbook

    I've searched and tested for a few hours now and can't seem to figure this out. I'm new to VBA so I can't custom create my own code.

    I have a folder of macro-enabled workbooks with non-standard naming. In each source workbook there is a worksheet called "Summary pg 1" that is a standard template form. I would like to have Cells G2, A14, A16, C17 and A19 from each workbook copied into its own row in a new workbook.

    SourceWorkbook1 to DestinationWorkbook1
    G2 = A1
    A14 = B1
    A16 = C1
    C17 = D1
    A19 = E1

    SourceWorkbook2 to DestinationWorkbook1
    G2 = A2
    A14 = B2
    A16 = C2
    C17 = D2
    A19 = E2

    Any help you can throw my way is highly appreciated.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,819

    Re: Copying cells from multiple workbooks into a new workbook

    Put this macro in a regular module of your master file. The macro uses "C:\Test\" as the location of your other files. Change this path to suit your needs. Don't place your master file in the same folder as your other files. Run the macro from your Master file.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    Thanks for the reply. Here's what I put inside the module:

    Please Login or Register  to view this content.
    I bolded the changes I made. I changed the path, the name of the Master spreadsheet and the destination sheet as Sheet2 instead of Sheet1.

    When I clicked the 'run' button, it processed for about a second then quit. No errors were generated and it did not update the master spreadsheet. The master spreadsheet is on the desktop and not inside the folder containing the source files. I have to enable macros on each of the source files as I open it, does that matter?

    Thoughts?

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    Hi
    if you click the button on sheet 1, it will open up a browse for folder screen, select the folder that contains the files to collate, then click ok.
    it will open each workbook, check for sheet(Summary pg 1) and then copy data into sheet1, close the source workbook and then open the next workbook etc.

    i've tested it and it works
    Attached Files Attached Files
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,819

    Re: Copying cells from multiple workbooks into a new workbook

    I created a couple of dummy source files and saved them in the same folder. I saved the master file on the desktop. It worked in my tests. Try having only the source files in your folder. It looks like you have a file named "Aerosol Master List.macro" saved in the folder with the other source files. Move this file to another location. Delete the line
    Please Login or Register  to view this content.
    and delete the "End If" that goes with it and give it another try.

  6. #6
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    Hi Mumps,
    I tried your code, really like how it loops through the files, haven't seen that method before.
    I also had a few problems but mainly due to finding last used row on master sheet.
    made some minor changes and works well.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    Quote Originally Posted by Sean Thomas View Post
    Hi
    if you click the button on sheet 1, it will open up a browse for folder screen, select the folder that contains the files to collate, then click ok.
    it will open each workbook, check for sheet(Summary pg 1) and then copy data into sheet1, close the source workbook and then open the next workbook etc.

    i've tested it and it works
    Thanks, this worked great! Saved me a ton of time!!

    Quote Originally Posted by Mumps1 View Post
    I created a couple of dummy source files and saved them in the same folder. I saved the master file on the desktop. It worked in my tests. Try having only the source files in your folder. It looks like you have a file named "Aerosol Master List.macro" saved in the folder with the other source files. Move this file to another location. Delete the line
    Please Login or Register  to view this content.
    and delete the "End If" that goes with it and give it another try.
    I double checked and I have only the source files in the folder. I removed the parts you outlined and it still did not pull in the data from the source files. Although the solution posted by Sean Thomas worked, I'm kind of curious why this didn't.

  8. #8
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    Quote Originally Posted by Sean Thomas View Post
    Hi Mumps,
    I tried your code, really like how it loops through the files, haven't seen that method before.
    I also had a few problems but mainly due to finding last used row on master sheet.
    made some minor changes and works well.

    Please Login or Register  to view this content.
    I just tried this by substituting the appropriate information and this generated a "208" dialog box with an OK button. Held the enter key so it cycled through each dialog and still no data input!

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,819

    Re: Copying cells from multiple workbooks into a new workbook

    @bigalpha: I'm glad you've got it working.

    @Sean Thomas: Thank you, Sean for your solution.

  10. #10
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    what did you change?
    the only things you need to change is
    Please Login or Register  to view this content.
    to your folder name
    and
    Please Login or Register  to view this content.
    to the name of your master document that contains this procedure. You only need to change this if your master workbook is in the same folder.

  11. #11
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    Share & share alike is my moto Mumps.
    Thanks for sharing your solution.

  12. #12
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    I changed:

    1. the path of my source folder
    2. "Master" to "Aerosol Master List.macro" [The code didn't work even if I left "Master" in place]
    3. "sheet1" to "sheet2" [I already have data on Sheet1]

  13. #13
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    can you post your full procedure?

  14. #14
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    Absolutely! This is the first set of code you provided that I changed (this includes removing the IF statement)
    Please Login or Register  to view this content.
    This is the revised code you provided:
    Please Login or Register  to view this content.

  15. #15
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    you need to change
    Const strPath As String = "C:\Users\alec.desantis\Desktop\Final"

    to

    Const strPath As String = "C:\Users\alec.desantis\Desktop\Final\"


    and hopefully as long as Aerosol Master List.macro is the name of your workbook it should work.
    without the \ it wont complete the file path

  16. #16
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    also you need to change this line
    Please Login or Register  to view this content.
    to Sheet2 for both cases otherwise you will not be getting the correct value

  17. #17
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    Okay, I made the changes to the initial set of code you provided and it worked great except that I received
    Please Login or Register  to view this content.
    instead of copying the value of the formula.

    The updated version of code provided did not work - it opened the source sheets but then gave a dialog box of "208".

  18. #18
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    Sorry you have lost me.
    where did you get that file path from? value of what formula?

    Error 208 is not a VBA error code,
    What causes error 208 ?The 208 error may be caused by windows system files damage. The corrupted windows system files entries can be a real threat to the well being of your computer.

    There can be many events which may have resulted in the system files errors. An incomplete installation, an incomplete uninstall, improper deletion of applications or hardware. It can also be caused if your computer is recovered from a virus or adware/spyware attack or by an improper shutdown of the computer. All the above actives may result in the deletion or corruption of the entries in the windows registry. This corrupted registry will lead to the missing and wrongly linked information and files needed for the proper working of the application.

  19. #19
    Registered User
    Join Date
    12-18-2013
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying cells from multiple workbooks into a new workbook

    Quote Originally Posted by Sean Thomas View Post
    Sorry you have lost me.
    where did you get that file path from? value of what formula?

    Error 208 is not a VBA error code,
    What causes error 208 ?The 208 error may be caused by windows system files damage. The corrupted windows system files entries can be a real threat to the well being of your computer.

    There can be many events which may have resulted in the system files errors. An incomplete installation, an incomplete uninstall, improper deletion of applications or hardware. It can also be caused if your computer is recovered from a virus or adware/spyware attack or by an improper shutdown of the computer. All the above actives may result in the deletion or corruption of the entries in the windows registry. This corrupted registry will lead to the missing and wrongly linked information and files needed for the proper working of the application.
    The field is a formula,
    Please Login or Register  to view this content.
    , that pulls in a piece of data from a different sheet . That formula pulls in text like this: "Aervoe, Fleet & Farm Multiple colors".
    The code provided by mumps1 pulled in the text instead of the formula.

    I'm on a government workstation, if that matters.

  20. #20
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Copying cells from multiple workbooks into a new workbook

    I'm still not sure what you mean.
    The cells you are getting values from the other workbooks, do they contain formulas?

+ 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. [SOLVED] Copying cells from multiple closed workbooks to active workbook
    By Anonym216 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 07:53 AM
  2. Conditioned copying/pasting of specific cells from multiple workbooks to master workbook
    By Ziad Homaidan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2013, 11:39 AM
  3. Replies: 1
    Last Post: 11-21-2012, 11:23 AM
  4. Replies: 1
    Last Post: 07-20-2012, 06:20 PM
  5. Copying Multiple worksheets in Multiple workbooks to one single workbook
    By ebrabender in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-28-2011, 02:30 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