How to import CSV data into multiple arrays and to return the multiple arrays via a function or sub in VBA?

excelvbalearner

New Member
Joined
Apr 16, 2018
Messages
6
I want to create a VBA add-in that imports a CSV file, split the data columns into separate arrays and returns these multiple arrays to the sub that calls this add-in. Not sure what is the best way to go about this.
For example, my data folder contains many CSV files where each has 5 columns of data (1st column is dates, and the remaining columns are numeric data. There is one line of header).
I also have several different workbooks that perform different types of analyses on these CSV files. Therefore, instead of reusing the same import csv data function or sub in each workbook, I want to create an add-in to perform this import function instead.
Ideally, this add-in will return 5 separate arrays for each CSV file. If not, I would be OK if it returns a 5-column array.
The code will look something like (where the SomeAnalysis Sub is in one of the Workbooks, ImportCSV is the add-in function or Sub and ncsv is the number of CSV files to be evaluated):


<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub SomeAnalysis()

For n = 1 to ncsv
[arr1,arr2,arr3,arr4,arr5]=ImportCSV(filename(n))
'Perform the analysis
next n

End Sub</code>
Appreciate any help. Thanks!

 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,818
Messages
6,181,152
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