+ Reply to Thread
Results 1 to 31 of 31

VBA to combine same worksheet in different workbooks into one without the heading

  1. #1
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    VBA to combine same worksheet in different workbooks into one without the heading

    Hi,

    I need help to combine worksheet named "Metal List" from different Workbooks who have many worksheets and the worksheet name "Metal List",into one sheet to get a consolidated data and I want it in a new workbook. I want the 1st row of all the merging sheets to be ignored as they contain the headings.

    I am using the below code but its not being very useful as it seems to copy the data of the first sheet twice!! and does not ignore the first row so there are multiple heading in the sheet.

    {If possible can it also automatically combine the worksheet "metal List" of workbooks saved in that particular folder or drive?}

    Please Login or Register  to view this content.
    Many Thanks for your help
    Last edited by varmoh; 02-27-2015 at 06:46 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: VBA to combine same worksheet in different workbooks into one without the heading

    Perhaps a macro like this? Macro loops through all files in a spcified folder (set by value of sPath) and opends every file and activate sheet"Metal List". If sheet not found file is closed and macro moves on to next file.

    Active range on sheet "Metal List" is copied with an offset of 1 i.e. no headings and pasted into the workbook where you run the macro from.

    Please Login or Register  to view this content.
    Alf

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Make a new workbook and Put some headings in the First row.
    Here is the code:-
    HTML Code: 
    Last edited by Vikas_Gautam; 02-27-2015 at 07:25 AM.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  4. #4
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Alf,

    Thank You for your reply,

    The macros is not running... I may not be following the right procedure.. can you just let me know If I am right, Moved all the relevant file to the folder called Metal,

    Opened a new workbook called Merged then click alt+F11, then inserted a new module, pasted the below code and then went to Tools-->Macros and ran that particular macros but nothing happened

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Vikas,

    Thank you so much for your reply!!...

    I used the code provided by you but I am getting an error "Excel cannot access "metal", The document maybe read only or encrypted". Any idea why I am facing this error?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading


  7. #7
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    One sec.

    You didn't suffixed "\"

    Try this code:-

    HTML Code: 

  8. #8
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Thank a Million it works!!!!!.... I do have one question.. will it automatically merge sheets from that folder when more workbooks are added or will I have to run the macros every time??? can it be done automatically?? because every time I run it...it copies from the beginning so if I have already copied data from two workbook and run it later...it copies the data from the new worksheet and also those two workbooks again
    Last edited by varmoh; 02-27-2015 at 08:15 AM.

  9. #9
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    No, you have to re run the macro when you add workbook to the Folder.

  10. #10
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Use the Revised Code Below.
    Now it will ask you the file using Open File dialog box. Give any file in the New Folder having new files in it.
    It will add at the end of the Existing sheet.

    HTML Code: 
    Last edited by Vikas_Gautam; 03-02-2015 at 03:28 AM.

  11. #11
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    HI Vikas,

    Thank You for your reply.

    I changed the macros and when I ran it the first time, it asked for a file so I chose the first excel and it copied all the three sheets "metal List", when I added a new workbook and ran it again it asked me for a file name and I chose the new workbook but it did not update the new info ..is there anything wrong that I am doing?

  12. #12
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    I have another question, its copying all the formatting and formulas as well... I want it to copy the values... can that happen??

  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: VBA to combine same worksheet in different workbooks into one without the heading

    Try changing

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Alf

  14. #14
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Alf,


    I changed the code but its still copying data validation filter and cell colour ...and is there are only 3 rows filled in a sheet, its still copying all the 200 rows which are coloured but no data in it...and some columns are with error #REF! as its copying the If(OR formula as well...

    Please help!!

  15. #15
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Alf is correct..
    You need to clear all the cells on the destination sheet. Just select all the cells and click "Clear All" button in the Editing Section of Home TAB.

    and Then re run macros.

    Using what Alf tells you.

    It will definitely do the job.

  16. #16
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi,

    I am not sure what I am doing wrong but I am not getting the right result... The code only gave me 3 lines with a row filled with #VALUE!.. please help

    Please Login or Register  to view this content.

  17. #17
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Can you provide some files to test with..?

    make a Zip file containing a Main file and some Extract file. and Upload.

  18. #18
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    May be there is something wrong with your input sheets..!

  19. #19
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Vikas,

    After testing the macros again, I have realised whats wrong with the source sheets,

    First, its picking up blank rows from the source sheet is it possible for it to pick only those rows with values and ignore blank rows as there are thousands of blank rows in the source spread sheet.


    Secondly, its picking up data from hidden rows and columns as well. Is it possible to amend the macro in order to ignore hidden cells in a spead sheet.


    I really appreciate your help and will look forward for your reply!!!

  20. #20
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Okay here is the amended code.
    Change the folder in the fPath variable and run the code.

    HTML Code: 
    Test and Tell.

  21. #21
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Vikas,


    Thank You for your response.

    When I run this macros, it says "Object Required", is there anything wrong that I am doing? Please help!

  22. #22
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Okay then Remove the Error Handler lines from the code.

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    and Run the code. Press Debug when Error comes.
    and Take a snapshot of the screen, Highlighting the Yellow line.

  23. #23
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Oh..!

    Did you changed the
    Please Login or Register  to view this content.
    and
    Sheet Name in the following line
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Vikas,

    Thank you for your response!!

    Please find attached the screen shot

    Error.jpg
    Attached Images Attached Images
    Last edited by varmoh; 03-02-2015 at 07:58 AM.

  25. #25
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    One more question..

    Do your excel files contain Formulas ..?
    I am talking about the Input files which are to merged.

    OR

    Can you provide me two input files to test with...?
    I won't take time then..

  26. #26
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Make a dummy Excel file and upload..!

  27. #27
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Vikas,

    Thank You for your reply and patience.

    I have attached two sample files that needs to be merged.
    Attached Files Attached Files

  28. #28
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    The Problem I got in your Input file was that that they were Protected with a password, hence not letting the code to work properly.
    So I make two unprotected copies of sheets to carry on with my test. However I have changed my code to unprotect sheet before moving on to copying data.
    Change the Pwd Variable holding password for your input files. I am Assuming there is only one password for all your files.

    Now come on to the Dropdown references your were talking about. I thing the best way to disregard them would be to move them to a new sheet ( say Drop Downs Sheet ). This is more appropriate as it won't be easy for me to capture only the data area as you said that there can be many empty rows as well.

    If you take care of all of above. The code will satisfy your needs very well.
    Here is the revised code. I am assuming there are 4 Header rows in all your Input files.

    HTML Code: 
    Test and tell. Don't forget to change the fPath variable and Pwd variable accordingly.
    Last edited by Vikas_Gautam; 03-04-2015 at 12:33 PM.

  29. #29
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Okay Varmoh..
    I think this project is counting its breath.
    I had to use an extra PwdBreaker code to unprotect sheet. Here is the Code:-
    HTML Code: 
    Post both of them alike in your VBA window and run the MergeIntoOneSheet Macro.
    Hopefully it would do the job as necessary.
    Last edited by Vikas_Gautam; 03-04-2015 at 04:25 PM.

  30. #30
    Registered User
    Join Date
    10-27-2014
    Location
    UK
    MS-Off Ver
    7
    Posts
    43

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Hi Vikas,

    It works like magic!!!!.. Thank you so much for all your efforts and patience....Greatly Appreciated!!!

  31. #31
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: VBA to combine same worksheet in different workbooks into one without the heading

    Thanks for this kind response ..! Varmoh

    Good luck.!

+ 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. Combine multiple read-only workbooks into one, each into separate worksheet
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2013, 03:23 PM
  2. How to combine multiple workbooks into one worksheet?
    By eajustin15 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2013, 02:42 AM
  3. combine data from multiple workbooks to a single new worksheet
    By ame in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2011, 08:12 PM
  4. How to Combine Separate Workbooks into One Worksheet
    By Wrecking_Crew in forum Excel General
    Replies: 2
    Last Post: 03-15-2007, 11:27 PM
  5. [SOLVED] Combine contents of multiple workbooks into one worksheet
    By EMG03 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-24-2005, 08:05 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