Hi,
I am newbie in Excel and VBA programming. I want to import CSV data from a file into Excel, but I am facing a problem when reformatting it. It is as follows:
In the CSV file I have the data as follows:
date, variable1, itsvalue
date, variable2, itsvalue
date, variable3, itsvalue
date1, variable1, itsvalue
date1, variable2, itsvalue
date1, variable3, itsvalue
date2, variable1, itsvalue
date2, variable2, itsvalue
date2, variable3, itsvalue
...
date_n, variable1, itsvalue
date_n, variable2, itsvalue
date_n, variable3, itsvalue
I dont know how many variables I will have. Maybe 3, or maybe 20. But, provided a specific csv file, I will have the same number of variables for each date. I want to load the data and reformat them in an excel worksheet file as follows:
DATE VARIABLE1 VARIABLE2 VARIABLE3 ... VARIABLE N date1 value1 value2 value3 ... value n date2 value1 value2 value3 ... value n date3 value1 value2 value3 ... value_n date4 value1 value2 value3 ... value_n ... value1 value2 value3 ... value_n date_n
I,e, I want to have one column per variable and its corresponding value for a date (date is in the format year-month-day-hour-min-seconds, e.g. 20131023104520, which corresponds to year 2013 month 10 day 23 and hour 10 min 45 seconds 20.
Since in the csv file I get the variables in a fixed period (e.g. each 10 seconds, so the date woould change each 10 seconds). This is my approach:
counter = 0
1. Read the seconds of the date
2. If ther seconds are equal to the seconds of the next wor increase a counter.
3. If seconds are different in the next row --> stop increasing the counter. The counter is now equal to the number of variables, and then I have a defined a block (number of variables recorded for a specific date, which will be always the same)
date1, variable1, itsvalue
date1, variable2, itsvalue
date1, variable3, itsvalue
4. With the aforementioned defined block, I think I could the formating I want in the worksheet.
Could someone point me out a way to do this? I need somehow first to get the number of variables and then to create the table in the worksheet.
Best regards,
-E
Bookmarks