+ Reply to Thread
Results 1 to 10 of 10

export decimal numbers to csv

  1. #1
    Registered User
    Join Date
    09-28-2016
    Location
    Mars
    MS-Off Ver
    2016
    Posts
    5

    export decimal numbers to csv

    I''m trying export from excel to csv
    the problem is the decimal numbers

    what I'm getting is this type of csv

    11,12;test

    what I want is a csv file like this

    "11,12",test

    so far I managed to run a VBA code just to replace the ; with , and export it in a text file

    Any help?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: export decimal numbers to csv

    How exactly are you exporting?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-28-2016
    Location
    Mars
    MS-Off Ver
    2016
    Posts
    5

    Re: export decimal numbers to csv

    I go to file -> export and change the file type
    I tried to export as CSV (comma delimited) and CSV (MS-DOS) or CSV (Macintosh)
    then used a VBA code to export in .txt

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,515

    Re: export decimal numbers to csv

    Choice of decimal separator and "list" separator (the character used to delimit .csv files) control how Excel chooses to create .csv files. These settings are in Windows Control Panel -- Region and Language settings. It looks like you currently have comma set as your decimal separator and semicolon as your list separator, and you want to have comma as both your decimal and your list separator. If that is the case, changing your list separator to comma should allow you to create the .csv files as you have described.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    09-28-2016
    Location
    Mars
    MS-Off Ver
    2016
    Posts
    5

    Re: export decimal numbers to csv

    I changed the list separator in Windows but didn't work. I have already solved the separator problem with a VBA code
    The extra step that I need is to get decimal numbers like 11,12 and export them inside quotation marks " " like this "11,12"

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,515

    Re: export decimal numbers to csv

    I don't know that we can make any suggestions without seeing the VBA code you are using. If I guess at the problem, you are probably not using enough quotation marks in your code. Since quotation marks are used to indicate string variables, in order to include quotation marks as part of a string, you must often nest the quotation marks within other quotation marks. For example:
    Please Login or Register  to view this content.
    When I execute this code, text1 contains the text string 11.12, where text2 contains the text string "11.12". I suspect that you need to do something similar with your VBA code -- nest the quotation marks within more quotation marks so that VBA will know to include a set of quotation in the string written to the .csv file.

  7. #7
    Registered User
    Join Date
    09-28-2016
    Location
    Mars
    MS-Off Ver
    2016
    Posts
    5

    Re: export decimal numbers to csv

    I'm using the export code that I found here
    http://www.cpearson.com/excel/ImpText.aspx

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,515

    Re: export decimal numbers to csv

    How well do you understand this code?

    The export string is created and stored in the variable wholeline in this loop:
    Please Login or Register  to view this content.
    Note the If then..else..end if block. This is the block that reads the cell value and stores the value in CellValue. Note how, in the first option where he tests for empty cells, how he use the Chr(34) function to return the double quote character, then uses the concatenate operator (&) to put two double quotes together and store them in CellValue. You should be able to do the same thing in the Else option to add double quotes around the Cells value. CellValue=chr(34)&cells(...).value&chr34&...

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: export decimal numbers to csv

    If your decimalseparator is "." like mine, then you would have gotten "11,12",test like I did. The quotes were added since 11,12 is a string and not a number for me.

    IF the decimalsepartor is "," then obviously, the results would not be the same.

    Play with these options. Reset or close/open Excel to restore the defaults if you play with such.
    Please Login or Register  to view this content.
    Then do your SaveAs CSV deal...

  10. #10
    Registered User
    Join Date
    09-28-2016
    Location
    Mars
    MS-Off Ver
    2016
    Posts
    5

    Re: export decimal numbers to csv

    I went to File->Options->Advanced and set decimal separator to ,
    I manages to change the list separator when exporting to csv with the VBA code
    but the problem is that it also changes the decimal separator from "," to "."

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 12-17-2015, 12:33 AM
  2. Replies: 3
    Last Post: 08-28-2013, 08:45 AM
  3. Replies: 4
    Last Post: 12-26-2012, 05:37 AM
  4. Replies: 2
    Last Post: 04-21-2010, 04:41 PM
  5. Replies: 4
    Last Post: 08-15-2006, 09:20 PM
  6. Too Many Numbers After The Decimal
    By RChicken in forum Excel General
    Replies: 4
    Last Post: 07-05-2006, 11:40 AM
  7. Decimal numbers not recognized as numbers
    By Stein Kristiansen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-13-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1