+ Reply to Thread
Results 1 to 15 of 15

Code that extracts specific sheet in multiple workbooks to one workbook

  1. #1
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Code that extracts specific sheet in multiple workbooks to one workbook

    Hi all! I have a folder on my desktop named "Test" that contains 400 workbooks with multiple sheets in each. What I need is a code that extracts the "Step2" sheet from each workbook in the folder. I want it to then create a new workbook with all 400 "Step2" sheets.

    Each sheet contains a different number of rows but is contained in columns A:J. There is also a header on each sheet in A1:J1.

    What I will eventually do is combine all sheets into one master sheet, but I figured it would be easier to split this function into two parts.

    Any help would be greatly appreciated! Thank you for reading!
    Last edited by KT999; 12-04-2014 at 09:58 AM.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Perhaps a macro like this would work for you?

    You must change the sPath ("C:\Temp\") to suit your needs as a desktop folder contains user name as well. This macro loops through all files and copies the "used range" on sheet2 so if there is more in column M, N .... this will be copied too.

    Macro also stips away headings.

    Please Login or Register  to view this content.

    Alf

  3. #3
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Thank you! Where would I put this code? in a blank file?

  4. #4
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    I cant get this to work. Ive tried pasting the code in both an existing and a new workbook, each in the sheet, workbook, and module. Not sure if I am doing something wrong?

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Did you change the "sPath" to the folder on the desktop where the files are found?

    Don't forget the last "\" the code will not work if you forget it.

    Adding the code to a workbook go to "Developers" click on "Visual Basic" icon. In the new windows that opends click on "Insert" and select "Module". Paste the code into the module.

    Close the "Microsoft Visual Basic" window. You are now back in the "Developer" tab. Click on the "Macros" tab in the pop-up window you should now see a macro (ProcessAllFiles) click "Run" and this should start the import.

    Alf

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Sorry my bad!

    Change the line

    Please Login or Register  to view this content.
    to this

    Please Login or Register  to view this content.
    Alf

  7. #7
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    I did both and it still doesn't work. all of the sheets are protected, I forgot to add that. I tried wrapping
    Please Login or Register  to view this content.
    but it still did nothing

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Ok so at the moment the password protection stops the macro from working. I'll do a bit of testing to see how to fix that.

    What you could do in the meantime is to record a macro where you go through all the steps, selecting a file, activating the "Stp2" sheet, entering password, do the copying and close the file.

    Could you post this macro, and if password shown in "clear" text replace that with *******.

    Alf

  9. #9
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Alf- first off thank you so much for your help, it is greatly appreciated.

    Second, I went in and manually unprotected the step2 sheet in 4 example workbooks. I put the code in a blank workbook module and it worked! Everything pasted in how I needed it to. The only issue was that a box popped up saying:

    "There is a large amount of information on the Clipboard. Do you want to be able to paste this information into another program later?"

    The code will only work if I select yes. My only concern is that the test data is relatively small compared to all the data I will have.

    Also, can we have it so it defaults to Yes and doesn't show the box?

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    "There is a large amount of information on the Clipboard. Do you want to be able to paste this information into another program later?"

    the line below should thake care of this I thought, but it don't seems to do that.

    Please Login or Register  to view this content.
    Then we better change the line

    Please Login or Register  to view this content.
    to this

    Please Login or Register  to view this content.
    and finaly

    Please Login or Register  to view this content.
    And the syntax for opening a password protected file is as you already have solved yourself is

    Please Login or Register  to view this content.
    If this solves you problem don't forget to mark your thread "Solved"

    Alf

    Ps
    To mark your thread solved do the following:
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

  11. #11
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    I get a syntax error on the
    Please Login or Register  to view this content.
    But your edits fixed the other problem!
    Last edited by KT999; 12-03-2014 at 05:58 PM.

  12. #12
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Strange, worked ok on my PC but as long as your syntax work then it does matter. Hmm I'll have to do a bit of testing to see if I can find out why my suggested setting for removing password did not work.

    At least I hope you got rid of the
    There is a large amount of information on the Clipboard.
    Alf

  13. #13
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    To things, yes the syntax is off (late evening in Gothenburg) proper syntax is


    Please Login or Register  to view this content.
    I'm not to happy with this part of the code as I feel it is a bit unstable

    Please Login or Register  to view this content.
    I think this is a better code

    Please Login or Register  to view this content.

    Alf

  14. #14
    Registered User
    Join Date
    12-01-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    Both changes worked (the password and the better code). Thank you so so much for hour help Alf! You have no idea how much I appreciate it!

  15. #15
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code that extracts specific sheet in multiple workbooks to one workbook

    You are welcome and thanks for the rep!

    Alf

+ 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] VBA Macro - One Excel sheet which extracts information from multiple sheets.
    By Defratos in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-13-2013, 05:36 AM
  2. [SOLVED] Run time error in code that extracts data from several sheets into master sheet
    By Hello23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2012, 10:11 PM
  3. [SOLVED] Edit code to close all workbooks except active workbook and other specific workbook
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2012, 09:29 PM
  4. Macro to extract data from multiple workbooks, specific sheet, specific cells
    By crissandraauree in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2012, 03:54 PM
  5. Replies: 1
    Last Post: 04-28-2011, 08:16 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