VBA importing .CSV dropping DATA not rows

gdougherty

New Member
Joined
Sep 30, 2015
Messages
1
We are importing some .CSV files into an Excel file. One column of data (ORDER NUMBER) typically contains NUMBERS (9992570000), the import works fine when this is the case.

However, some data in this column contains ALPHA CHARACTERS within the data (999TX50000); when this scenario occurs this DATA is not imported.

The "row" of data is imported, but this ORDER NUMBER data is dropped.

For example:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]ORDERNUMBER[/TD]
[TD]COL2[/TD]
[TD]COL3[/TD]
[TD]COL4[/TD]
[/TR]
[TR]
[TD]ROW1[/TD]
[TD]9992570000[/TD]
[TD]TEXAS[/TD]
[TD]WABASH[/TD]
[TD]BILL[/TD]
[/TR]
[TR]
[TD]ROW2[/TD]
[TD][/TD]
[TD]IOWA[/TD]
[TD]FRANKFORT[/TD]
[TD]JOE[/TD]
[/TR]
</tbody>[/TABLE]






Code:
 With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
        "ODBC;DefaultDir=\\Omaw2kfile02\lozier\BPA\llcAutoKey;Driver={Microsoft Text Driver (*.txt; *.csv)};DriverId=27;Extensions=txt," _
        ), Array( _
        "csv,tab,asc;FIL=text;MaxBufferSize=2048;MaxScanRows=25;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;" _
        )), Destination:=Range("$A$3")).QueryTable
        .CommandText = Array( _
        "SELECT *" & Chr(13) & "" & Chr(10) & "FROM " & Filename & ".csv " & Filename & "" & Chr(13) & "" & Chr(10))
        
        'MsgBox "SELECT *" & Chr(13) & "" & Chr(10) & "FROM " & Filename & ".csv " & Filename & "" & Chr(13) & "" & Chr(10)
        
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = False 'True GD
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Table_Query_from_csvFiles"
        .Refresh BackgroundQuery:=False
    End With

Appreciate any insight!!
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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