Dynamic field parser/importer

nsaint

New Member
Joined
Sep 29, 2008
Messages
3
I am asking for help from the experts on this forum.
<o:p> </o:p>
I need to import a CSV file into Excel and do a number of things with the values imported (that is not important right now). The problem I am having is with the import - with the number of fields and the order in which the fields appear in the CSV. In the CSV I need to import, there are 512 fields – more than excel can handle. That is o.k., because I don’t want all of them initially and not the problem I am having. I know how to browse to the file and import the data, skipping the fields I don’t need. The problem is the fields sometimes change position on the line. For instance, Field1 is sometimes first and other times 10th or something else, but it is always called Field1.
<o:p> </o:p>
So I would like to have the user provide a list of fields to get and then figure out where they are on the line so I can know which to import and which to skip.
<o:p> </o:p>
It seems like I need to read the first line into an array, search for the items I need, figure out the position they hold and then map that to my ActiveSheet.QueryTables.Add(…..).TextFileColumnDataTypes = Array(1, 9, 9,….) to know which ones I have to skip and which ones I have to read in.
<o:p> </o:p>
When using two files, Test1.csv and Test2 I want to be able to dynamically find Field10 and get the data in that column (0.92 in this case)
<o:p> </o:p>
<o:p> </o:p>
Any help is greatly appreciated.
<o:p> </o:p>
File One: Test1.csv
Field1,Field2,Field3,Field4,Field5,Field6,Field7,Field8,Field9,Field10
0.92,1.08,0.18,0.17,1.80,0.26,1.91,0.49,1.47,0.92
<o:p> </o:p>
File One: Test2.csv
Field10,Field4,Field6,Field2,Field3,Field5,Field9,Field8,Field7,Field1
0.92,2.08,0.38,0.11,3.60,1.2,0.91,0.5,1.7,1.2
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I have received help on another forum, but will thank any addition info or other ideas on how to solve this problem.

Looking into using an ADO connection
 
Upvote 0

Forum statistics

Threads
1,203,072
Messages
6,053,377
Members
444,659
Latest member
vuphihung

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