+ Reply to Thread
Results 1 to 5 of 5

Macro to convert decimal separators from US to EU format when loading a CSV file?

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    San Francisco, CA USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Macro to convert decimal separators from US to EU format when loading a CSV file?

    To accommodate a number of clients who run Excel with German locale settings and need to open CSV files that contain US formatted data, I am looking for a way to write a macro that automates the various steps to make this switch (the "problem" here is that the decimal separator is a period in the US and a comma in Germany whereas the thousand separator is a comma in the US and a period in Germany). Without changing the setting, the data is not recognized properly.

    Is it possible to combine the following steps in a macro - all of it or portions of it?

    -In Excel 2010, select Data, then "From Text" in "Get External Data"
    -It opens a file selection window; select the CSV file you want to open, click "Import"
    -For file origin, select "65001: Unicode (UTF-8)" - click next
    -leave "Tab" as the delimiter and click next
    -click "Advanced" and select the comma for decimal separator and period for thousand separator - click finish

    The idea here is to get this macro to the clients so they can run it instead of the steps above every time the want to open a file with US formatted data.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Macro to convert decimal separators from US to EU format when loading a CSV file?

    Start the macro recorder, do all the steps you describe, then stop the macro recorder. The generated VBA code will hard-code the selected CSV file name, but this can be easily changed (edited) to call Application.GetOpenFilename so that the user can browse and select the CSV file and then use the returned file name instead of the hard-coded file name.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    11-05-2012
    Location
    San Francisco, CA USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to convert decimal separators from US to EU format when loading a CSV file?

    Thanks Chippy, super helpful.
    Just to get the final step right: what portion of the recorded macro do I need to replace with Application.GetOpenFilename? Or is it: call Application.GetOpenFilename

    Here are the first few lines:

    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;C:\Users\kgrossmann\Desktop\kwd20.csv", Destination:=Range("$A$1"))
    .Name = "kwd20"
    .FieldNames = True
    .
    .
    .

  4. #4
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Macro to convert decimal separators from US to EU format when loading a CSV file?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-05-2012
    Location
    San Francisco, CA USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to convert decimal separators from US to EU format when loading a CSV file?

    Works like a charm,
    thanks Chippy!

+ 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