I opened semicolon delimited txt file with this code below and long account number showed up as scientific notation after saving to excel regardless of formatting to text that column.
What did I do wrong here?
Application.ScreenUpdating = False
Workbooks.OpenText fileName:=Filetxt, Origin:=xlWindows, StartRow _
:=2, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False, _
Space:=False, Other:=False, Local:=True, _
FieldInfo:=Array(Array(1, 4), Array(2, xlTextFormat)
'Save text file as csv file
Set wb = ActiveWorkbook
Application.DisplayAlerts = False
wb.SaveAs fileName:=fileXls, FileFormat:=6, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = True
wb.Close savechanges:=True
Record in txt file looks like this: 2011-12-21;100,00;"21375000120000010020601764"
And when I open newly saved file I see 2.117500012E+25 instead of that number. what's wrong here?
Unfortunately excel does not allow you to turn this functionality off by default. However if you select your data, right click, and click "Format cells..." and choose Number you can stop excel from changing your data to scientific notation.
(1) Right-click a cell where you want to remove scientific notation, and (2) choose Format Cells… 2. In the Format Cells window, (1) select the Number category, (2) set the number of decimal places to 0, and (3) click OK. Now the scientific notation is removed.
I was importing products into an excel file and the barcodes would come up as a scientific notation (eg 5.4265E+12)
This meant when I converted the file into a csv file to upload the details, the csv wasn't reading the barcodes properly and changing them to 52862300000 etc.
To combat it:
This should convert them all to display as the long number. You can then save it as a CSV file and the numbers won't be converted/formatted into scientific numbers.
Hope this helps!!
In Excel numbers are limited to 15 digits of precision. Your example number is too large for Excel to represent accurately - that may explain the conversion to scientific notation.
You should import that column into Excel as Text, not Number: then you won't lose any precision.
EDIT: if you step through the "open from text" process while recording a macro you should get something like this:
Workbooks.OpenText Filename:= Filetxt, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 5), Array(2, 1), _
Array(3, 2)), TrailingMinusNumbers:=True
There is a step in that process which allows you to select what type of data is in each column.
Your "FieldInfo" paramter is a bit off I think: you should have 3 columns, but you've tagged col2 as text...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With