Hi Emil,
I guess you may have this one done then in the meantime?
If you have it is always good to share the solution.
I just answered an almost identical Thread, jus a lot more complicated.
So while it was fresh in my head, I did a quick mod to it to get it to do what you want.
So i thought it would be a useful contribution to this thread.
_...........................................................
The code I give here is actually much too complicated with extra unnecessary bits that your application does not need. But I will leave it that form for now. The extra stuff may slow things down a bit, but as a prototype to get anyone going on a similar requirement it allows a bit of flexibility. I deliberately am using lots of different ways of doing things as a learning exercise ( for me!! ). I have not extensively tested it yet, but it takes the files you gave me and gives the results you wanted.
So the basic idea is.....
The requirement
Bring any number ( within reason ) of ( Excel ) .csv files in a folder that have a form something like this.............
Using Excel 2007
Row\Col A B C 1Start Tid Forbrug Enhed 22014-01-01 00:00:00 +0100 0.01kWh 32014-01-01 01:00:00 +0100 0.01kWh 42014-01-01 02:00:00 +0100 0.01kWh 52014-01-01 03:00:00 +0100 0.01kWh 62014-01-01 04:00:00 +0100 0.01kWh
Data file 2
________...Into a Master Sheet in a Excel, so , for example, with Three such Files you end up with This
Row\Col A B C D E F G H I J 1Data file 1 Data file 2 Data file 3 2Start Tid Forbrug Enhed Start Tid Forbrug Enhed Start Tid Forbrug Enhed 32014-01-01 00:00:00 +0100 31.6999999999971 kWh 2014-01-01 00:00:00 +0100 0.0100000000002183 kWh 2014-01-01 00:00:00 +0100 1.0 kWh 42014-01-01 01:00:00 +0100 31.6000000000058 kWh 2014-01-01 01:00:00 +0100 0.0100000000002183 kWh 2014-01-01 01:00:00 +0100 1.0 kWh 52014-01-01 02:00:00 +0100 30.8999999999942 kWh 2014-01-01 02:00:00 +0100 0.0100000000002183 kWh 2014-01-01 02:00:00 +0100 1.0 kWh 62014-01-01 03:00:00 +0100 30.4000000000015 kWh 2014-01-01 03:00:00 +0100 0.00999999999930878 kWh 2014-01-01 03:00:00 +0100 1.0 kWh 72014-01-01 04:00:00 +0100 32.5 kWh 2014-01-01 04:00:00 +0100 0.0100000000002183 kWh 2014-01-01 04:00:00 +0100 1.0 kWh 8
Ark1
( That is a screenshot BTW taken for after a run if the code, so it seems to work. )
There can be any amount of columns and rows in the csv files ( within reason )
You are asked for the Folder containing the csv Files
You are asked for the separator ( In your files it was a __ ; ___ )
The code is currently set to put data in a master Worksheet of name “Ark1” in the same file as you put the code in.
The code is here:
http://www.excelforum.com/showthread...t=#post4326024
And here:
http://www.excelforum.com/showthread...t=#post4326025
Note it is all one code. ( I had to split it as it was too big for a single post. ) The second part should be copied directly under the first part in the same Module. That can be a normal Code Module or a Sheet Code module.
I may come back and edit / change it a bit as i notice anything as Ii work on the other Thread i am looking at )
Alan
P.s.
The basic idea wot the code is doing:
Rem 1) Rem 2)
Gets the folder and Separator Info from you
Rem 4 )
Makes a temporary copy of that Folder including all the files in it.
Rem 5 )
This is the “Dir” Loop, doing stuff for each of the csv files the Duh "chucks up"
So for each of them, ( it loops while “Dir” chucks something up )
Changes the .csv to a .txt File ( and Puts it in another Temporary folder ) ( Rem 5a) Rem 5b) )
Rem 5c)
This is the main doing stuff based closely on the original Codes I gave. Just has a Minor mod to put data for each inputted File at the next free column and puts the file name at the top left of each data set.











LinkBack URL
About LinkBacks


Register To Reply

Bookmarks