+ Reply to Thread
Results 1 to 10 of 10

Need macro to open multiple file,copy and paste in a new spreadsheet

  1. #1
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    109

    Need macro to open multiple file,copy and paste in a new spreadsheet

    Hi guys,

    I'm extremely new to macro but I'm thinking macro should be able to do this:-

    I got 12 excel files, let's name it A.xlsx, B.xlsx, and so on, and each located at different directory:

    For example:

    C:\Desktop\New Folder 1\A.xlsx
    C:\Desktop\New Folder 2\B.xlsx
    C:\Desktop\New Folder 3\C.xlsx
    C:\Desktop\New Folder 4\D.xlsx
    C:\Desktop\New Folder 5\E.xlsx
    C:\Desktop\New Folder 6\F.xlsx
    C:\Desktop\New Folder 7\G.xlsx
    C:\Desktop\New Folder 8\H.xlsx
    C:\Desktop\New Folder 9\I.xlsx
    C:\Desktop\New Folder 10\J.xlsx
    C:\Desktop\New Folder 11\K.xlsx
    C:\Desktop\New Folder 12\L.xlsx

    All the excel files, from A.xlsx to L.xlsx, I want to copy cell A397:M403 and paste into a spreadsheet

    Note that A397:L397 are merged cell, the rest are no-merge cell

    For file A.xlsx to F.xlsx, I want it to be copy and paste into new spreadsheet on the left hand, and for file G.xlsx to L.xlsx, I want it to be copy and paste on the right hand side, so that I can view side by side as per the draft below:-

    A.xlsx G.xlsx
    A397:M403 A397:M403

    B.xlsx H.xlsx
    A397:M403 A397:M403

    C.xlsx I.xlsx
    A397:M403 A397:M403

    D.xlsx J.xlsx
    A397:M403 A397:M403

    E.xlsx K.xlsx
    A397:M403 A397:M403

    F.xlsx L.xlsx
    A397:M403 A397:M403

    Currently it's too manual to open one by one and copy paste in a monthly basis
    And for some reason, when i paste in formulae, next month when I open the file, the formulae are in chaos before I replace the formulae with new file (due to new directory...)

    Hope to hear soon from macro-expert here....

    Let me know if there's enquiry..

    Thanks

    regards
    cks1026

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    MultiFileProcess.xlsm
    See if this does the trick.
    Last edited by natefarm; 01-16-2014 at 02:28 PM. Reason: Updated attachment as requested in later post
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    Hi natefarm,

    First of all, thank you for follow up my issue.

    The format from this macro is exactly what I wanted !!
    But...there's one small issue...

    All the spreadsheet from A.xlsx to L.xlsx range from A397:M403 are with formulae such as SUM, AVERAGE, etc
    After run the macro, all the cell are returning #REF!

    Is there any chance that you can adjust the macro code by linking every cell to the relevant spreadsheet, so that when the relevant spreadsheet had adjustment, re-run the macro will capture the latest adjustment in this MultiFileProcess.xlsm

    If this is not possible, then paste all in value with the same format from relevant spreadsheet will do.

    Thanks

    Regards
    cks1026

  4. #4
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    If this is not possible, then paste all in value with the same format from relevant spreadsheet will do.
    I updated the attachment to copy values. I didn't know how to do it with links.

  5. #5
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    Hi natefarm,

    For some reason, after you updated the attachment to copy values, couple of issues occurred.

    1.) There's run time error '1004' stated PasteSpecial method of Range class failed.
    When I click debug, it points to this row ---- > ThisWorkbook.Sheets("Results").Cells(ToRow + 1, ToCol).PasteSpecial (xlPasteValues)

    2.) the format of the 12 sources excel file are not being copied and paste into similar format

    Please advice.

    Thanks

    Regards
    cks1026

  6. #6
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    I don't know why. It works fine when I run it. Of course, I just created by own test input files, but I don't know why it would make a difference. You could try recording a macro where you do the copy - paste special, and maybe make some adjustments. Of course, recorded macros throw all kinds of extra unneeded code in there.

  7. #7
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    Can I just check with you if these code works when copy the merge cell and paste special in merge cell format as well?

  8. #8
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    I'm unclear on what you are asking. Are there merged cells in the range you are copying, or in the destination you're copying to? That might cause complications. If so, try unmerging the cells, and then try the code.

  9. #9
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    yes, that's what I'm asking.... there are merged cell I'm copying to new destination.....

  10. #10
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need macro to open multiple file,copy and paste in a new spreadsheet

    Please try unmerging the cells first, and then try the code.

+ 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] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  2. macro to open, copy paste from existing excel file to a new blank file
    By 2blessed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2012, 06:05 PM
  3. Copy, open file, and paste macro
    By Ohaern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2011, 11:45 AM
  4. macro to open file - copy - then paste into other file possible??
    By Kezwick in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-13-2011, 07:59 AM
  5. Replies: 1
    Last Post: 10-17-2005, 04:05 AM

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