+ 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

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

    Hi guys I am kinda new here, so forgive me if I had missed the "Introduction part".

    My name is Mike. I am 24. I am finishing my Master's degree and I am one inch to get it, so I need your guys help!

    I know it's simple for the most of you, but I am kinda new in this (though I've worked with Excel for maaany...manyy years i.e. from Windows 3.1 till today) but I had never had to encounter such a problem.

    The thing is I wanna copy C6:Z8, from each sheet on a 30 Sheet Excel file, and to do that with 12 sheets. So roughly that is 360 sheets C6:Z8.

    The issue on hand it's 1 year (and there are 14 years) of raw data from a water treatment factory, that uses water and the quantity of water is measured on a hourly basis 0-24.

    So for an example. On a excel file for July 2004, I have 31 sheet for the days, and 24 values for three pipes.

    All that data from January to December for each day I want to group it into ONE visualization (graph) that will show the quantaty of water.

    I haven't done VBA, or macro's so...please point how to do that.

    I am using MS Excel 2007 and ...help pls!

    Thanks!

    Mike

  2. #2
    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

    Anyone??? Please help me

  3. #3
    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

    You need to provide more information.

    Are the workbooks all in 1 folder?
    What is the naming convention for the workbooks?
    What is the namiing convention for the worksheets?

    It would help if you could post an example workbook with say 2 days worth of information. What is important is the data layout, you can use dummy values for the actual data points.
    Cheers
    Andy
    www.andypope.info

  4. #4
    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.

  5. #5
    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

  6. #6
    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

  7. #7
    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

  8. #8
    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!

+ 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