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:
ORDERNUMBERCOL2COL3COL4
ROW19992570000TEXASWABASHBILL
ROW2IOWAFRANKFORTJOE

<tbody>
</tbody>






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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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