+ Reply to Thread
Results 1 to 9 of 9

How to consolidate data from multiple excel files into single sheet in new book?

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    9

    How to consolidate data from multiple excel files into single sheet in new book?

    Hi All,

    Presently I have multiple excel files in one folder, I need a vba code which does the below activity.

    Open all the excel files one after the other in ascending order and paste the data in new workbook in a single sheet.

    All files contain headers, but I want header to be copied and pasted only once and not every time multiple excel files are opened.

    For example: Book A and Book B contains data from 1st row to 100th row (including header). I want data to be copied 1st row to 100th row (including header) of Book A and paste in Book Consolidated, copy data from 2nd row to 100th row (exclude header) in Book B and paste it in 101st row in Book Consolidated.

    Let me know if you have any questions.

    Any help is much appreciated.
    Attached Files Attached Files
    Pradeep M B

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Hi arlu1201,

    This code helped me. I need two more favor on this.

    1)If column A is not blank in any of the multiple excel files, need to insert a blank column.

    2)If column A is blank, need to check if value (date) in cell "O1" is the same in all the multiple workbooks.

    Please advise.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Regarding question 1, insert a blank column in the source file or the destination file?

    Regarding question 2, if O1 is the same in all workbooks, what should be done?

    if its not same, what should be done?

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Answer to 1, blank column should be inserted in source file, so that the earlier macro copies the blank column to destination file also. (As of now, blank column in "A" is already present in all source files and so in destination file. This is fine now).

    Answer to 2,

    Dates in Header (1st row) in all source files begin from O1 and will be monthly wise in m/d/yyyy format.

    if Value in "O1" is same in all files, continue the code how it is working now. Some files might have different values (date) in O1.
    If it is different, then delete that column and look in 1st (header) row for the value in O1 in other files.

    For example: in the attached files, value of O1 is 3/1/2013, this should be same in all source files which gets reflected in destination file also..

    if O1 is 2/1/2013, then delete that column so that P1 which contains 3/1/2013 comes to O1.

    Please let me know if you need any further information.

  6. #6
    Registered User
    Join Date
    03-27-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Friends,

    Any help on the above?

    Please help with this part of coding.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Here is the updated code which includes inserting column A if its not blank.
    Please Login or Register  to view this content.
    Regarding this,
    For example: in the attached files, value of O1 is 3/1/2013, this should be same in all source files which gets reflected in destination file also..

    if O1 is 2/1/2013, then delete that column so that P1 which contains 3/1/2013 comes to O1.

    Please let me know if you need any further information.
    How would the macro know which is the right date in O1? What if the 1st file picked up itself does not have the right column? Is it ok if a msgbox is provided to the user which will popup to ask for the date? Then this date will be matched to the columns starting in O and then proceed accordingly.

  8. #8
    Registered User
    Join Date
    03-27-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Hi arlu1201,

    Thanks for providing code which includes inserting column A if its not blank.

    Ok, msgbox can be provided to the user to ask for the correct date.

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to consolidate data from multiple excel files into single sheet in new book?

    Try this code - i have now included the part where it checks for the date and deletes the column if its not the current date.

    Please Login or Register  to view this content.

+ 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