How to import long number from csv to excel without converting to scientific notation in VBA

前端 未结 7 1475
青春惊慌失措
青春惊慌失措 2021-02-05 10:07

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

相关标签:
7条回答
  • 2021-02-05 10:25

    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:

    1. open the Mac os software "Numbers" and create a new tab
    2. copy data to tab, you will see correct number
    3. open Microsoft excel change number columns "cells format" to text
    4. copy data from Numbers tab;
    5. right-click "Optional paste" select Text and ok.

    I don't know why but it works for me.

    0 讨论(0)
  • 2021-02-05 10:25

    It looks like you are using a text file as an input. Steps:

    1. Go to cell A1
    2. File -> Open -> select the .txt file -> Open
    3. Text Import Wizard will open. Go through steps 1, and 2 according to your input file format. For step three, do this:
    4. 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.

    0 讨论(0)
  • 2021-02-05 10:43

    Insert an apostrophe before the number. This forces Excel to display the whole number.

    0 讨论(0)
  • 2021-02-05 10:45

    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...

    0 讨论(0)
  • 2021-02-05 10:46

    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 
    
    0 讨论(0)
  • 2021-02-05 10:46

    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.

    0 讨论(0)
提交回复
热议问题