skip columns when importing *.csv

ExcelChick

New Member
Joined
Jun 25, 2002
Messages
6
I want to import some, but not all, columns from a *.csv file. I am trying to do this with VBA because I then have to do a bunch of other things with the data (replace values, rearrange the columns, etc.) and I want to do it all with one button.

My code works just fine if the file is named *.txt. But if I try this on the same file named *.csv ALL the columns import. Also, I need to import some "number" columns as text. Again, works fine on the *.txt, but not the *.csv.

Can anyone offer some insight on how to get this to work. (a solution other than renaming the file first :biggrin: )

Thank you
Code:
file = Application.GetOpenFilename()

Workbooks.OpenText Filename:=file, Origin:=437, StartRow:=1 _
        , DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True _
        , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 9), Array(2, 9), _
        Array(3, 9), Array(4, 1), Array(5, 1), Array(6, 2), Array(7, 2), Array(8, 9), Array(9, 1), _
        Array(10, 1)), TrailingMinusNumbers:=True

ps. the file I importing is 48 columns, I only show few above to make it easier to read.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I appreciate the quick response, Oorang, but could you elaborate. I do not know what you mean.

Thank you.
 
Upvote 0

Forum statistics

Threads
1,207,402
Messages
6,078,270
Members
446,324
Latest member
JKamlet

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