VBA to copy rows base on date from a reference cell

wallstudio

New Member
Joined
Oct 19, 2010
Messages
36
I need VBA to copy rows from one of thousands of csv files in the same directory. The file name structure of csv is "(000#)_ABCD.csv", where number inside bracket is 4 digits, and the "ABCD" is the name code.

There are 6 columns in each csv, with ascending date in column A.

In my WB, A1 is date, B1 is the number code of csv file. However, the format is regular number showing "1" instead of "0001".

The VBA need to refer to the number in B1 and open the csv file from the directory. Then copy a year range of data from the csv and paste to the WB starting from A3 with A1 value as the latest date. That means, if A1 is 1/1/2011, the date range to be copied should be 1/1/2010 to 1/1/2011. Then, the csv need to be closed also.

Thanks for the help.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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