+ Reply to Thread
Results 1 to 13 of 13

Copying data from multiple files (with mult. sheets) into one file and create a graph

Hybrid View

  1. #1
    Registered User
    Join Date
    04-28-2010
    Location
    Macedonia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    1) Yes all my workbooks are in E:\Data\

    For an example 2002: E:\Data\2004\April 2004.xls

    2) For the worksheets 01.04.2004; 02.04.2004; 03.04.2004 etc.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    So you can create code to loop thru month/years and extra daily information.

    If you need more help post example workbook
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-28-2010
    Location
    Macedonia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    If you can see h1,h2,Qkanal are divided into 0-24 hours with data in those fields.

    So I need to extract all thouse data which is divided the same way on multiple sheets and excel files.

    I've attached examples from January 2004, and April 2004.

    After I extract that data into one excel files I must create a graph or a visualization of the water quantities ...
    Attached Files Attached Files

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    This will process the files, although you will have problems as the data layout is not consistent.

    You will need to update the vntMonths array to have the regional names you give to each month.
    Also extend the lngYear loop to cover years you have data for, by changing the last value in the For Loop.

    Sub ConsolidateData()
    
        Dim wbkData As Workbook
        Dim shtData As Worksheet
        Dim shtOutput As Worksheet
        Dim strPath As String
        Dim lngYear As Long
        Dim lngMonth As Long
        Dim vntMonths As Variant
        Dim strName As String
        Dim strFilename As String
        Dim lngOutRow As Long
        Dim lngRow As Long
        Dim lngHour As Long
        Dim lngDay As Long
        
    ' Update regional month names 
        vntMonths = Array("", "Januari", "F", "M", "April", "M", "J", "J", "A", "S", "O", "N", "D")
        strPath = ThisWorkbook.Path & "\"
        
        Set shtOutput = ThisWorkbook.Worksheets("Sheet1")
        lngOutRow = 2
        Application.ScreenUpdating = False
        For lngYear = 2004 To 2004  ' change last 2004 to latest year
            For lngMonth = 1 To 12
                strName = vntMonths(lngMonth) & " " & lngYear & ".xls"
                strFilename = Dir(strPath & strName)
                If Len(strFilename) > 0 Then
                    Set wbkData = Workbooks.Open(strPath & strFilename)
                    lngDay = 1
                    For Each shtData In wbkData.Worksheets
                        shtData.Range("C6:Z8").Copy
                        shtOutput.Cells(lngOutRow, 2).PasteSpecial xlPasteValues, , , True
                        lngHour = 0
                        For lngRow = lngOutRow To lngOutRow + 23
                            shtOutput.Cells(lngRow, 1) = DateSerial(lngYear, lngMonth, lngDay) + TimeSerial(lngHour, 0, 0)
                            lngHour = lngHour + 1
                        Next
                        lngOutRow = lngOutRow + 24
                        lngDay = lngDay + 1
                    Next
                    wbkData.Close False
                End If
            Next
        Next
        Application.ScreenUpdating = True
        
    End Sub

  5. #5
    Registered User
    Join Date
    04-28-2010
    Location
    Macedonia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    Where I can write this code and how to run it? I know it's a macro, but pls tell me the way to do this.

    Thanks anyway. I appreciate this very very much!

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    Create a workbook.
    ALT+F11 to goto VBE
    Insert Code Module in to the project
    Paste code

  7. #7
    Registered User
    Join Date
    04-28-2010
    Location
    Macedonia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copying data from multiple files (with mult. sheets) into one file and create a g

    I have to create a new Excel file, and save it in the file of the 2004 files and Alt+11 and run the code as a module?

+ 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