+ Reply to Thread
Results 1 to 10 of 10

Import file and convert decimal point to comma

  1. #1
    Registered User
    Join Date
    04-10-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2012
    Posts
    9

    Import file and convert decimal point to comma

    Hi,

    Ive run into this issue and cant solve it. I searched the internet and this forum and came across similar topics but with no success of good working code in the end. I have excel 2012 and i have the following problem.

    Daily i want to import this file with text and numbers. So i do that via data tab> import from text etc. But when i import it, the numbers are with decimal points not commas (i live in EU, need comma). So its 2040.50 instead of 2040,50. Just replacing with a formula for another column is not really an option for me.

    What macro should i use to
    a) easier import this file with a one click or so macro
    b) convert numbers so that they are with decimal commas instead of pointsa and as a 'number' so i can do calculations

    For a) I used http://support.microsoft.com/kb/213816 script from Microsoft, but now looking for a way to combine it with b) also.

    Thanks in advance.
    Last edited by veniw; 04-17-2013 at 08:00 AM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Import file and convert decimal point to comma

    convert . to ,

    Select column.

    CTRL + H

    find . (punt) (dot)
    replace by (komma) (comma)

    replace all.

    This can also be added in an macro.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    04-10-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2012
    Posts
    9

    Re: Import file and convert decimal point to comma

    Hi Oeldere, thanks for your quick reply. But im not looking for the replace function usage. I know i can do that. But i have to import this file every day or so and dont want to keep doing that.

    How can i do that with a macro? Thats what im looking for.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Import file and convert decimal point to comma

    For your b) question you could test this macro and see if it works for you.

    Please Login or Register  to view this content.
    To get help with your a) question you stand a better chanse getting help if you upload a sample text file.

    Alf

  5. #5
    Registered User
    Join Date
    04-10-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2012
    Posts
    9

    Re: Import file and convert decimal point to comma

    Hi Alf,

    your solution for b) works perfect, thanks!

    With this post i uploaded a sample text file.

    And if you have a macro for that, can I then just merge the two macro actions in (so between "Sub ()" and "End Sub" where I put the macro for opening the file before the replacement thing so it processes in that order?
    Attached Files Attached Files

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Import file and convert decimal point to comma

    This macro imports a specific file from a specific folder. You will have to change the file name and the folder to suit your needs.

    Excel also had some problem "converting" 3.2800000000000002 to number (there was 2 or 3 more like that. It seems Excel could not cope with this and made a number without any delimiter 18 digits long. So I had to test cells and if they contained 18 numbers if so the macro chops them down to 8 a number that Excel seems to be happy with.


    Please Login or Register  to view this content.
    Alf

  7. #7
    Registered User
    Join Date
    04-10-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2012
    Posts
    9

    Re: Import file and convert decimal point to comma

    wow, that is awesome thanks a lot! This is the perfect thing. I appreciate it you looked into the file and made sure that those big numbers are now also converted properly

    One last question remains. By running this macro it imports the data perfectly. But, if i want to do some calculations with it and then later import the file again (say next day, with new data). How would you go about this?
    Because right now, if i run the macro again to import the data, no matter what cell or column is selected, it always imports it next (right side) to the data previously imported into the file. Also, it overwrites any data in those cells, where my calculations are.
    I would prefer to have it below or above the before-imported data.

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Import file and convert decimal point to comma

    Macro adjusted i.e. using "Offset" command imported files will be placed beneath each other.

    Was not too happy with my first "error" trapping so I've changed it to check for a "." in the cell value and that the number of "values" must be 18 or bigger. If both conditions are fulfilled then it will find the position of "." and add 3 so you will get 3 decimals after the "."

    If this is not sufficient increase 3 to 5 or 6.

    Please Login or Register  to view this content.
    Alf

  9. #9
    Registered User
    Join Date
    04-10-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2012
    Posts
    9

    Re: Import file and convert decimal point to comma

    Hi Alf,

    Sorry for my late response. Your solution works perfect, thanks for your help!

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Import file and convert decimal point to comma

    No problem! Thanks for feed back and as your problem now seemed solved could you please mark it "Solved"

    Alf

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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