+ Reply to Thread
Results 1 to 9 of 9

How to copy data from multiple workbook from multiple subfolder

  1. #1
    Registered User
    Join Date
    08-01-2020
    Location
    Viet nam
    MS-Off Ver
    2007, 2010
    Posts
    17

    How to copy data from multiple workbook from multiple subfolder

    Hi all

    I have work book Total.xlsm with sheets(Main, A001, B002, C003, D004,E005,F006)
    Total.xlsm is the same path with alot of folders: 202006,202005,202004,202003,......201912,20201911,201910,...etc (Folder have name like yyyymm)

    Now I want to have macro to do this:
    1. Check each Folder name with range("A2: lastrow)
    2. If meet folder.name will check 4 characters of each excel name with: Left(excel_filename,4) = Range("B2:lastrow")
    3. If Filename exist will copy data to Total.xlsm like:
    Left(excel_filename,4) = "A001" then copy data to workbook("total").sheets("A001").Range("A1")
    Left(excel_filename,4) = "B002" then copy data to workbook("total").sheets("B002").Range("A1")
    Left(excel_filename,4) = "C003" then copy data to workbook("total").sheets("C003").Range("A1")
    Left(excel_filename,4) = "D004" then copy data to workbook("total").sheets("D004").Range("A1")
    Left(excel_filename,4) = "E005" then copy data to workbook("total").sheets("E005").Range("A1")
    Left(excel_filename,4) = "F006" then copy data to workbook("total").sheets("F006").Range("A1")

    Please help me./.
    Attached Files Attached Files

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: How to copy data from multiple workbook from multiple subfolder

    Not tested, but possibly...
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-01-2020
    Location
    Viet nam
    MS-Off Ver
    2007, 2010
    Posts
    17

    Re: How to copy data from multiple workbook from multiple subfolder

    thanks #dangerlor but code don't work.
    Code have twice "lrow" in thisworkbook.sheets("main")

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: How to copy data from multiple workbook from multiple subfolder

    Can you be more specific as to what didn't work?

  5. #5
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: How to copy data from multiple workbook from multiple subfolder

    Partially tested on some fake folders and files.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-01-2020
    Location
    Viet nam
    MS-Off Ver
    2007, 2010
    Posts
    17

    Re: How to copy data from multiple workbook from multiple subfolder

    Dear Dan

    Your code work but there're have some problem is:

    1. For each vFolders have a lot of files wiht name the same 4 first characters, for examble in Folder 202006 have file: A001-123456.xlsx, A001-234567.xlsx etc...
    => So your code copy only one file, not all file begin wiht A001 in filename.

    2. Range copy data must be in range as I wrote in my code like:
    All file name with A001 must be copy Sheets("A0011").Range("B19:F50")
    All file name with B002 must be copy Sheets("B0021").Range("B19:C50")
    All file name with C003 must be copy Sheets("C0031").Range("B19:E25")
    All file name with D004 must be copy Sheets("D0041").Range("B19:F40")
    All file name with E005 must be copy Sheets("E0051").Range("B19:G20")
    All file name with F006 must be copy Sheets("F0061").Range("B19:B20")

  7. #7
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: How to copy data from multiple workbook from multiple subfolder

    Sorry for the delay...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-01-2020
    Location
    Viet nam
    MS-Off Ver
    2007, 2010
    Posts
    17

    Re: How to copy data from multiple workbook from multiple subfolder

    Thanks Dan, Code work perfect

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: How to copy data from multiple workbook from multiple subfolder

    Thanks for letting me know!

+ 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] Copy data from multiple WorkBook structures to the same sheet on another workbook
    By tax112 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-16-2018, 09:43 AM
  2. Copy the Data from Multiple workbook to Master Workbook as Conslidated
    By venugosr in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-19-2017, 01:32 AM
  3. Replies: 2
    Last Post: 01-22-2016, 08:03 PM
  4. Replies: 0
    Last Post: 09-18-2015, 03:20 AM
  5. Replies: 9
    Last Post: 02-13-2015, 05:12 AM
  6. Replies: 12
    Last Post: 07-29-2014, 01:06 PM
  7. Copy data from multiple sheet in multiple books into a new summary workbook
    By dobba in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2014, 08:14 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