+ Reply to Thread
Results 1 to 6 of 6

Copying data across workbooks in the same folder to masterfile

  1. #1
    Registered User
    Join Date
    10-27-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    8

    Copying data across workbooks in the same folder to masterfile

    Hi,

    I have multiple excel workbooks that I need to copy into a masterfile within the same folder.

    Each workbook would have the same template as the masterfile.

    There are 4 sheets in each workbook that need to be transferred specifically to the respective sheet in the masterfile.

    I have tried modifying codes such as the one below mentioned, but i can't get it to work.

    Sub LoopThroughDirectory()
    Dim MyFile As String
    Dim erow
    Dim Filepath As String
    Filepath = "C:\Test\"
    MyFile = Dir(Filepath)
    Do While Len(MyFile) > 0
    If MyFile = "TEST.xlsm" Then
    Exit Sub
    End If

    Workbooks.Open (Filepath & MyFile)
    Range("A2:D2").Copy
    ActiveWorkbook.Close

    erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    ActiveSheet.paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 4))


    Loop

    End Sub

    Any help would much appreciated.

    Thank you.

  2. #2
    Registered User
    Join Date
    10-27-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    8

    Re: Copying data across workbooks in the same folder to masterfile

    I think using the above code to copy a single sheet over but it copies the sheet in the masterfile instead. May I know why?

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Copying data across workbooks in the same folder to masterfile


    Hi,

    According to forum rules, you must use code tags !

    Try to add Activesheet before the Range.Copy

  4. #4
    Registered User
    Join Date
    10-27-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    8

    Re: Copying data across workbooks in the same folder to masterfile

    Hi Marc,

    Thanks for the reminder.

    The problem was due to the code not being run in a module.

    Below is the current code now:

    Please Login or Register  to view this content.
    Is it possible to copy a range from a specific worksheets in a workbook as paste it in the respective sheets in the masterfile?

    As mentioned there a 4 different sheets to the copied and pasted respectively.

    E.g.

    Workbook1's sheet1's range = Master Workbook's sheet1's next empty row
    Workbook1's sheet2's range = Master Workbook's sheet2's next empty row
    Workbook1's sheet3's range = Master Workbook's sheet3's next empty row
    Workbook1's sheet4's range = Master Workbook's sheet4's next empty row

    then it continues to loop through the rest of the files in the folder

    thank you

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Sample …


    To copy worksheets from MyFile workbook to code workbook :

    PHP Code: 
        For N% = 1 To 4
            With ThisWorkbook
    .Worksheets(N).UsedRange.Rows
                Workbooks
    (MyFile).Worksheets(N).UsedRange.Copy .Item(.Count).Cells(1)(2)
            
    End With
        Next 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Registered User
    Join Date
    10-27-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    8

    Re: Copying data across workbooks in the same folder to masterfile

    hey marc, works great! thank you

+ 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 info from variable workbooks to a masterfile then loop
    By batuh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2014, 03:51 PM
  2. [SOLVED] Copying data from specific cells in multiple Workbooks in a folder and Consolidating it
    By Tristanfrontline in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2014, 11:27 PM
  3. Copying all EXCEL workbooks in a Folder to one master workbook
    By HitTheEXCELerator in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2013, 10:42 PM
  4. copying data from excel files in a source folder to target folder
    By Javed07 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 04:27 PM
  5. Copying only certain cells from all workbooks in a folder and placing them in a list
    By marymary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-25-2010, 12:46 PM
  6. Copying workbooks to a new folder retaining relative links
    By mangoeater2 in forum Excel General
    Replies: 1
    Last Post: 06-08-2010, 11:00 AM
  7. Copying workbooks to another folder
    By F6Hawk in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-05-2007, 08:34 PM

Tags for this Thread

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