Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removal of Leading Zeros When Importing Data Into Excel

Status
Not open for further replies.

bdbBear

Programmer
Apr 29, 2005
54
US
I'm using the following code to import data stored in a .txt file into an Excel (XP) file:

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Filename, Destination:=Range("A8"))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With

The data looks like this:

0054632 0.03
0056434 0.016
0056650 0.207

Although the values in the first column are all numeric, they need to be imported as text in order to keep the leading zeros. Unfortunately, when I run the code, it brings in the data and removes the leading zeros. The number formatting of the cells where the data is imported into are set to text.

Does anyone know why Excel is not seeing these values as text and removing the leading zeros; also, is there a way to fix this?

Thanks!

 
Have a look at the TextFileColumnDataTypes property of the QueryTable object

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top