+ Reply to Thread
Results 1 to 3 of 3

Copy specific data from different range of files saved in different folders

Hybrid View

phoenixwright Copy specific data from... 01-21-2013, 02:44 AM
antoka05 Re: Copy specific data from... 01-21-2013, 04:42 AM
phoenixwright Re: Copy specific data from... 01-21-2013, 07:47 PM
  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    Manila
    MS-Off Ver
    Excel 2010
    Posts
    3

    Unhappy Copy specific data from different range of files saved in different folders

    Please help!

    I need a macro that will get the same data, say the Prices for 24 hours of a day and will place the data to A1 to A24 until the end date's 24th hour.

    The data need are saved in a file with the date as part of the filename (YYYYMMDD) and the file is saved in a folder named with the date as part of the folder name as well (YYYYMMDD).

    For example: I need the 24 hour prices for December 26, 2010 to January 25, 2011.
    The December 26 file is Report_20101226.xlsm, which is saved in folder with name Reports_20101226.
    Each of the dates in a month are saved as well in the same directory, so for December 2010 the directory is X:\Reports\2010\12_December\.
    Each of the month folders are saved as well in the same year directory, so for January 2011 the directory is X:\Reports\2011\01_January\ and so on.

    I'm new to VBA and had enrolled in a class but it will start on March.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Copy specific data from different range of files saved in different folders

    See attached file where I used this code:
    Sub getData()
       Dim myDate As Date, newWb As Workbook, myFileName As String
       
       myDate = ThisWorkbook.Sheets("sheet1").Range("b1")
       'file name: x:\reports\yyyy\mm_monthname\reports_yyyymmdd\reports_yyyymmdd.xlsm
       myFileName = "x:\reports\" & Year(myDate) & "\" & Format(Month(myDate), "00") _
                  & "_" & MonthName(Month(myDate)) & "\Reports_" & Format(myDate, "yyyymmdd") _
                  & "\Reports_" & Format(myDate, "yyyymmdd") & ".xlsm"
    
        Application.ScreenUpdating = False
        Set newWb = Workbooks.Open(myFileName)
        'copy range a1:a24 from opened workbook
        newWb.ActiveSheet.Range("a1:a24").Copy ThisWorkbook.Sheets("sheet1").Range("b4")
        newWb.Close False
        Application.ScreenUpdating = True
    End Sub
    Regards,
    Antonio
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-21-2013
    Location
    Manila
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Copy specific data from different range of files saved in different folders

    thanks much,, will use it

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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