I am trying to consolidate a specific range of date from many csv files. What I want to do is to select this range and paste it into a master sheet in a separate workbook. The .csv files are all arranged in one folder and all have 1 sheet in the same format. The range can be dynamic so this code will need to be able to select all the rows below a cell or be able to delete blank rows from a larger range. I would appreciate any help.
Thanks
I've used a batch file to something like this in the past. This code does not handle deleting Aggregate.csv if the batch file is ran again.
Once in Excel, you can delete all the header rows and filter date ranges with VBA. You can also use VBA's Shell method to aggregate with Copy.
Edit: You can also create a data source in Other Data Sources > MS Query in order to query Aggregate.csv with Microsoft Text Driver using date ranges, etc.
Some pointers how to go about the solution:
First, enumerate the files using the FileSystemObject.
Declare
fso
,fld
,file
asObject
.LoadFile
will be a function you have to write, which processes a single file. It will look approximately like this:The function opens the file; then searches the first column for the interval to copy; then copies the cells and closes the file.
The code is not runnable as-is, but should hopefully give you the right ideas.