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 c
My system is mac os X El Capitan , when I copy data to Excel from html table, the number always auto convert to 1.10101E+17 etc. when I change "cells format" to text, the number is incorrect.
My resolve is:
I don't know why but it works for me.
It looks like you are using a text file as an input. Steps:
- Go to cell A1
- File -> Open -> select the .txt file -> Open
- Text Import Wizard will open. Go through steps 1, and 2 according to your input file format. For step three, do this:
- Use the mouse to select the column that gives you the headache, long account numbers, in your case. Under 'Column data format' select the 'Text' radio button, then, click Finish.
You will be good to go.
Insert an apostrophe before the number. This forces Excel to display the whole number.
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...
Select the cells where the foramt should be changed:
'Example:
Columns("A:E").Select
Selection.NumberFormat = "0.00"
Selection.NumberFormat = "0.0"
Selection.NumberFormat = "0"
'The exponential or scientific notation will be converted
I have a solution that works for me with a text file tab delimited.
Open the text file in notepad etc..
Copy the text file with Ctrl-A and Ctrl-C then Ctrl-V into a blank sheet.
Note all the columns that look scientific.
Then Ctrl-Z (undo). You should now have a blank worksheet.
Highlight all columns (Ctrl-Click on each column header) that you noted before.
Change format to Text
Click on first cell and Ctrl-V again.