+ Reply to Thread
Results 1 to 13 of 13

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

  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,436

    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,436

    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,436

    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.

    Please Login or Register  to view this content.

  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!

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

    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

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

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

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

    That is correct

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

    GREAT! It's working! Man you just changed my LIFE :D hahaha A BIIIIIIIIIIIIIG PACK OF BEER FOR YOU!

    Ok, now to ask u about the code


    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


    This part its the declaration of variables right?

    ' Update regional month names
    vntMonths = Array("", "Januari 2004", "Februari 2004", "Mart 2004", "April 2004", "Maj 2004", "Juni 2004", "Juli 2004", "Avgust 2004", "Septemvri 2004", "Oktomvri 2004", "Noemvri 2004", "Dekemvri 2004")
    strPath = ThisWorkbook.Path & "\"


    Strange enough the original code you've sent me, worked well...this code with the name of the months (the filenames of xls) were not working (strange).

    Ok, I understand from C programming what is Array. vntMonth is the variable. strPat it's for what?

    Set shtOutput = ThisWorkbook.Worksheets("Sheet1") ' Does this meens that can only work if the file where the data gathered it's named Sheet1 or I can change it here and Save As? '
    lngOutRow = 2 ' Creating two rows for h1 and h2 ? '
    Application.ScreenUpdating = False ' ??? '
    For lngYear = 2004 To 2004 ' change last 2004 to latest year
    For lngMonth = 1 To 12
    strName = vntMonths(lngMonth) & " " & lngYear & ".xls" 'I understand the meaning but not the function of this part'
    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


    Ok, for this part it's almost all clear I have to just put my finger on my forehead and scratch a bit :D

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

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

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here


    First bit variables, yes.

    The array is for month names, I used this because you use Januari where as in the UK we would use January. So I guess other months will also be spelt differently.

    You have also used that array of Months to include Years. This is not necessary. The years are controlled by the For Next loop with the lngYear index variable. Simply change where I had the comment 2004 to the latest year you have data files for.

    strPath is the folder location for the file to be processed. It is stored in the variable as the returned information from the DIR function is filename only.
    So the path is required for DIR and Workbooks.Open

    Sheet1 is the name of the output worksheet. If you want to rename the tab you can just rename it in the code as well.

    strName build the filename to search for.

    Application.Screenupdating turns of screen updates. This means the screen does not flash as all the files are opened and the sheets processed. It also speeds execution.

+ 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