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.
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.
So you can create code to loop thru month/years and extra daily information.
If you need more help post example workbook
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 ...
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
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!![]()
Create a workbook.
ALT+F11 to goto VBE
Insert Code Module in to the project
Paste code
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?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks