+ Reply to Thread
Results 1 to 30 of 30

Converting US data to EU data in one operation through VBA?

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Converting US data to EU data in one operation through VBA?

    Hi all,

    I'm a Norwegian resident interested in obtaining daily data of the S&P 500 index. This can be done for free through Yahoo Finance:

    S&P 500 Daily Data.


    The problem is that the US seems to use different separators, both between columns and for decimals (comma "," in EU and "." in US). The result is that when I download this data, all is contained in one column.

    A solution for this is to:

    1) Use the "Text to column" function to split the data into columns;

    2) Use the "Seek and replace" to switch from "." to ",".

    This is of course a cumbersome process on a daily basis.

    Sadly, I have no experience with VBA, but I was wondering if it's possible to create a script that does this all in one go? I could then have a sheet with raw data directly from Yahoo and a second sheet with converted data.

    Or maybe there is a smarter solution?

    Back in the day I had the same problem and changed my system settings from EU to US. However, I have a looooot of sheets now in EU format, so it's not really a workable solution.

    Thanks in advance for any help.

    Elijah
    Attached Images Attached Images

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: Converting US data to EU data in one operation through VBA?

    Hi and welcome to the forum

    Pictures are of little value. Honestly, no one wants to re-type your data to try and solve your issue. Additionally, we would only be guessing at how your data was structured, ie. formulas, formatting, etc. Additionally, due to how some browsers behave, many of our members cannot see uploaded pictures/images. Please do not take this route.

    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" of what you wish the output to be.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Hi, Alan,

    I appreciate the comment.

    I have had some great help on this forum in the past and I always make it a point to attach Excel files. The reason I didn't do it this time is because I suspected US residents will get the sheet correctly displayed instead.

    I am now uploading a sheet where all the steps I take are detailed in separate sheets:

    1. Raw data *.csv is downloaded from Yahoo through this link.

    2. I use the function "Text to columns" to convert the data from one column to 7 columns as it should be. This is done for me by choosing "Comma" as separator.

    3. Seek and replace all "." with ",". By the way, my Excel often tends to freeze/crash when doing this if the data set is large.

    4. Finally, format my data to numbers with two decimals.


    I did attach pictures on all the sheets to show how they look on my computer. They're pasted in on the right side of each sheet.

    Finally, I had to save the data in another format than *.csv since it had multiple sheets, so I saved it in original Excel format.


    In summary, my problem is that I can obtain the data easily, BUT, I need to go through many steps to get it in European format. Since this is a process I'd like to do on a daily basis, I'd love it if there were a simpler solution.
    Preferrably, I'd find a data provider in Europe, but I don't know anyone who supplies this for free...

    Thanks in advance.
    Attached Files Attached Files
    Last edited by Elijah; 02-04-2018 at 06:11 AM.

  4. #4
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    It seems like I forgot to add the files yesterday!

    The original file was too large to upload, so I zipped it. If zip is a problem, I did make a smaller version deleting a few thousand rows of data to make it smaller. Also removed the pictures...

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Converting US data to EU data in one operation through VBA?

    Here is the macro code.
    ARRAY(1,4) is for DMY for date. Depending upon requirement chnge 4 to other number.

    Please Login or Register  to view this content.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Converting US data to EU data in one operation through VBA?

    or maybe so
    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    After download, don't open csv via Excel.

    Run the code from the fresh workbook and let's see how it goes.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Wow! Thank a lot, guys! Truly appreciate the effort.

    All the code ran well (it's the first time I've used VBA, so I had to google a little to understand how to proceed), but only nilem's code accomplished what I wanted (except formatting with two decimals at the end).

    kvsrinivasamurthy - separates the data into columns, but it's still "." as separator.

    jindon - uses semicolon as separator

  9. #9
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    nilem,

    Not sure if it's possible without too much trouble, but would it be possible to output the data with two decimals only?

    I.e., 2686,1001 = 2686,10

    Not sure why there's so many decimals anyway? Maybe an additional error due to US/EU conversion issues in format?

    The norm for this data is two decimals as can be seen here:

    https://finance.yahoo.com/quote/%5Egspc?ltr=1

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    jindon - uses semicolon as separator
    Please Login or Register  to view this content.

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Converting US data to EU data in one operation through VBA?

    Quote Originally Posted by Elijah View Post
    ...Not sure why there's so many decimals anyway?...
    Look at the CSV file, there are 6 decimal places
    Date,Open,High,Low,Close,Adj Close,Volume
    1950-01-03,16.660000,16.660000,16.660000,16.660000,16.660000,1260000
    1950-01-04,16.850000,16.850000,16.850000,16.850000,16.850000,1890000

  12. #12
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Converting US data to EU data in one operation through VBA?

    Instead of doing find/replace you should be able to just change the format/region.

    Also I presume you are opening the csv directly into Excel (by double clicking it). You may instead open Excel first and use the text import wizard (basically Text to columns) which may let you both split up the columns and format in 1 movement.

    Of course if you do this very frequently a macro cant hurt to help speed it up as others have offered.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  13. #13
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Quote Originally Posted by nilem View Post
    Look at the CSV file, there are 6 decimal places
    Date,Open,High,Low,Close,Adj Close,Volume
    1950-01-03,16.660000,16.660000,16.660000,16.660000,16.660000,1260000
    1950-01-04,16.850000,16.850000,16.850000,16.850000,16.850000,1890000
    Yes. I was wondering if perhaps it's an error due to format/region when I'm downloading it...

    Quote Originally Posted by Zer0Cool View Post
    Instead of doing find/replace you should be able to just change the format/region.

    Also I presume you are opening the csv directly into Excel (by double clicking it). You may instead open Excel first and use the text import wizard (basically Text to columns) which may let you both split up the columns and format in 1 movement.

    Of course if you do this very frequently a macro cant hurt to help speed it up as others have offered.
    Yes, but that's in my Excel settings, right? Wouldn't that render my sheets made in my current region obsolete? I'm pretty sure that happened the last time I attempted this.

    The text import wizard is pretty neat. I wasn't aware of that function. Still, I don't seem to be able to replace "." with "," using that one.

    EDIT: It does seem like I can replace the "." with "," in the wizard, but it does involve editing.

    So, the VBA from nilem seems to be my best bet for now. I can simply format the data to numbers with two decimals and have saved some time for sure.

    Thanks again for all help! Much appreciated!
    Last edited by Elijah; 02-05-2018 at 03:40 PM.

  14. #14
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Quote Originally Posted by jindon View Post
    [code]
    Appreciate it, jindon, but it seems like I'm still getting some errors on this one...

  15. #15
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Hi again, everybody,

    I think the data I initially posted may be OK, but I discovered somewhere else that delivers data that I know for sure is better.

    The problem is that this data is in *.txt format.

    I tried using the Text Import Wizard suggested by Zer0Cool and by several cumbersome steps, I AM able to get everything right:

    1. Open Wizard

    2. Select Edit

    3. Change Date

    4. Change "." to "," on the numbers (not date)

    5. Change the numbers from text to decimal numbers

    6. Finally import to Excel

    7. Format as numbers with two decimals in Excel

    I'd hate to ask since I already got help with the *.csv, but it would of course be great if this could be done using a macro similar to what I already got already.

    I'm attaching both the Excel (with picture embedded in case conversion makes it look different on your computer) of how it should look like and the raw data in *.txt in case anyone should feel up for it.

    Thanks.
    Attached Files Attached Files

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    For the txt file uploaded.
    Please Login or Register  to view this content.

  17. #17
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Converting US data to EU data in one operation through VBA?

    or maybe with minor changes
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Hey guys,

    Really appreciate the effort, but I'm sad to say that neither worked 100%. Actually, it was Jindon's which were closest.

    The numbers were correct, although they weren't formatted as numbers with two decimals. That's not a big deal. I can fix it myself...

    But the date was a little off from the regional format here. This means that when formatting this as a table, Excel doesn't recognize it as a date which makes sorting hard.

    I'm attaching a picture of how it looks on my screen and how I envisioned it side by side.

    Thanks again.
    Attached Images Attached Images

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    Then how about
    Please Login or Register  to view this content.
    Edit: Added lines for decimal separator to a comma.
    Last edited by jindon; 02-06-2018 at 02:36 PM.

  20. #20
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Great! Thanks a lot, Jindon!

    Works very well with the dates.

    Finally, the numbers are now formatted as "Standard". Some have two decimals. Some have 1 decimal. Some have zero decimals.

    For me, it's a couple of clicks to format the data into numbers with two decimals, so either way I'm happy.

    Or do you have any ideas on how to integrate that in the macro?

    If not, no worries! I'll marked this as solved anyway.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    See if this rounds up to 2 decimals...
    Please Login or Register  to view this content.

  22. #22
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Yes, Jindon, it does! Fantastic!

    Let me know if you're in Norway. I'm buying beer!

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    You are welcome and thanks for the rep.

    OK, thanks for the offer...

  24. #24
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Hi again,

    I started to play around a little with the data.

    Finally, I'd like to format this data in a table. I'm attaching a sheet to show how it's done.

    Of course, it's not much work to paste the raw data produced by the macro into a table in a separate sheet, BUT, it would be very nice if the macro could insert this
    data in row 2 instead.

    If so, I imagine that I could simply update the table directly using the macro? And also overwrite older data when updating the *.txt file?

    The column with "1s" in F is superfluous also. Not sure what it's doing there really...

    Would this be a quick fix in the macro? If so, I'd be very grateful.
    Attached Files Attached Files

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    Do you want it like this?
    Please Login or Register  to view this content.

  26. #26
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Absolutely great, Jindon!

    Would there be a way to not include column F with the "1s" when making the conversion?

    PS: Wasn't able to give you more reps.

  27. #27
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    Please Login or Register  to view this content.
    The code only reads first 5 columns from text file.
    Do you want all 6 columns?

  28. #28
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Hi, Jindon,

    Sorry, my bad. It works exactly as it should already. I only want the first 5 columns. I was very tired this morning, so must have messed up something.

    Thanks again.

    A final question from me, although I hate to ask for more help...

    Is it possible to import the data from the *.txt file displaying the newest dates on top, i.e., from newest to old? The opposite of how it's currently displayed?

    I figured I could switch this fast myself using the sort function, BUT, the problem is that doing this seems to disrupt some of the formulas I'm making in additional columns.

    If not, no worries of course. But it would be so nice if this is possible as I've gotten a great worksheet now that's fast to use thanks to your help.

  29. #29
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Converting US data to EU data in one operation through VBA?

    If you want it sorted by Date then change to
    Please Login or Register  to view this content.

  30. #30
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Converting US data to EU data in one operation through VBA?

    Hi, Jindon,

    I just tried it now very fast and it appears to work great! Thanks again! Really appreciated.

+ 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. [SOLVED] The data necessary to complete this operation is not yet available
    By amartinez988 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2016, 11:30 AM
  2. [SOLVED] Losing Data When Converting Delimited Data From Text To Column
    By sandubandu in forum Excel General
    Replies: 3
    Last Post: 01-15-2016, 05:25 AM
  3. Converting multiple columns to rows / Converting to Panel Data
    By Stuart11 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2013, 05:50 AM
  4. Replies: 5
    Last Post: 09-11-2012, 03:45 PM
  5. Replies: 0
    Last Post: 07-03-2012, 09:36 AM
  6. Replies: 5
    Last Post: 04-23-2010, 08:01 AM

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