+ Reply to Thread
Results 1 to 2 of 2

Code to copy, paste data of sheet 1 of several files in a folder to a main summary sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    03-28-2013
    Location
    Chicago, US
    MS-Off Ver
    Excel 2007
    Posts
    1

    Code to copy, paste data of sheet 1 of several files in a folder to a main summary sheet

    Can anyone pls provide the code to copy paste the data in the first sheet of several files from a seperate folder into a summary file. The copied data will be have to be pasted with values and formats from the source file. Can the macro automatically open and copy the data from each file and then automatically close each file. Finally the summary sheet should have all the data from the sheet 1 named "TimeEntry" from all the files in the folder.
    As i am new to vba programming, would it be possible for anyone to help me with the code for the macro to run successfully?

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Code to copy, paste data of sheet 1 of several files in a folder to a main summary she

    Maybe:

    Sub Steve2014()
    
    Dim CurFile As String, DirLoc As String
    Dim Dest As Worksheet
    
    DirLoc = ThisWorkbook.Path & "\STEVETEST\" 'location of files
    CurFile = Dir(DirLoc & "*.xls")
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Set Dest = Sheets("Summary")
    
    Do While CurFile <> vbNullString
        
        Dim OrigWb As Workbook
       
        Set OrigWb = Workbooks.Open(Filename:=DirLoc & CurFile, ReadOnly:=True)
    
        CurFile = Left(Left(CurFile, Len(CurFile) - 5), 29)
    
        OrigWb.Sheets("TimeEntry").UsedRange.Copy Dest.Range("A" & Rows.Count).End(3)(2)
        
        OrigWb.Close SaveChanges:=False
        CurFile = Dir
        
    Loop
    
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    
    Set Dest = Nothing
    
    
    End Sub
    Note: In this case the Activeworkbook with the Summary sheet cannot be in the same folder it will have to be saved to the folder afterwards.

+ 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