+ Reply to Thread
Results 1 to 3 of 3

Macro to copy data from multiples files

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2009
    Location
    Quebec, Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro to copy data from multiples files

    Hi,
    I need to make a macro to sum consecutive data (ex:f7:f26) in sheet3 of every files begining by 08-xx-xx.xls in the E:/data/test folder and copy the result in the sheet1 cell A2,A3,A4,etc... of my compilation.xls file in the same E:/data/test folder. If someone have any idea on how to do that, your help will be very welcome!
    thanks!

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro to copy data from multiples files

    p1rate78,

    This works in my test environment.

    The macro will not open the files. It will create formulae in your workbook, and then change the formulae to values.

    And, it will copy the filename into column B, as a reference.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Press and hold down the 'ALT' key, and press the 'F11' key.

    On the 'Insert' menu, click 'Module'.

    Copy the below code, and paste it into the Module (on the right pane).


    
    Option Explicit
    Sub GetData()
    Dim MyDir As String, FN As String, SN As String
    myDir = "E:\data\test folder"
    sn = "Sheet3"
    Application.ScreenUpdating = False
    FN = Dir(MyDir & "\08*.xls")
    Do While FN <> ""
      If FN <> ThisWorkbook.Name Then
        With ThisWorkbook.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp)(2)
          .Formula = "=SUM('" & MyDir & "\[" & FN & "]" & SN & "'!F7:F26)"
          .Value = .Value
          .Offset(, 1).Value = FN
        End With
      End If
    FN = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub

    Then run the "GetData" macro.


    Have a great day,
    Stan
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    04-04-2009
    Location
    Quebec, Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up Re: Macro to copy data from multiples files

    It's working fine!
    Tanks Budy!

+ 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