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

前端 未结 7 1476
青春惊慌失措
青春惊慌失措 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: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...

提交回复
热议问题