Importing a concatenated CSV file into Excel, but headers not on new rows(?)

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
This is probably a problem with the Batch file command I'm using to combine the separate CSV files, but here is problem:

I have 100 separate CSV files in a folder that I'm merging into a single CSV file with a simple .Bat batch file that I run from that folder with this code:
Code:
copy /a *.csv concat.csv

Each separate CSV file is in identical format with 25 columns (A:Y), though some have more rows than others. Here's what the first few rows of every file looks like:
pvQAPsq.jpg


I expected the merged CSV to have those same 25 columns, with each all of the data simply stacked on top of each other. HOWEVER, when I run the above batch file to merge them into one, the merged file looks like this (look at cell Y238 in yellow):
FU4Q5Of.jpg



So what's happening is that my batch script is indeed merging all the CSV files into 1, but for some reason combines the LAST cell of one file ("28.209" in the image above) with the FIRST cell ("Date") of the next file. The result is that the header row of each successive file stretches way out to column AW as you can see in the pic above.

So just how do I tweak my Batch code that is combining the CSV's so that it puts the data from each individual CSV file on a new row in the merged file? I've read and tried 10 different scripts I've found online and can't get this to work :/
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Actually, I used to use VBA code very similar to that, which looped through 100+ CSV files, and imported them one after another into the same worksheet, but it took around 30 seconds (during which Excel was unusable), and so I thought I'd hit the jackpot when I discovered that I could use a batch file like in my OP to instantaneously merge all the CSV files into 1...it did indeed cut my import time by like 90%, but now I have the problem I started this thread hoping to solve with the mis-aligned headers. I figured there'd be a minor tweak to the batch file, which would simply avoid the header problem altogether, so that I could continue to merge them all with a click prior to import...spent a lot of time googling 'merge several CSV files with batch file' and variations of it, but can't get anything to work...
 
Upvote 0
I find if a process is known to be long I use a message box to forewarn. The other things are how close to excel is the data you are drawing down, over a network there will be some latency
 
Upvote 0
Bumping to see if anyone with some batch-file know-how can give me any ideas here...(i guess it's more of a batch file help request than strictly excel, but they're related enough that I thought I'd give it a go...)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top