+ Reply to Thread
Results 1 to 9 of 9

Need a hand to clean up working code (External Data fetch foreign exchange rates)

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Post Need a hand to clean up working code (External Data fetch foreign exchange rates)

    I have created some code to fetch the USD exchange rate from a bank website. When the workbook is opened, it runs in the background to fetch the data from the website and then displays the Buy/Sell rate and the date & time that these rates were current at.

    The code works fine however it was originally created using Macro Recorder. I have tidied it up from the original recording however it needs improving. What I am looking for is a condensing (is that a word?) of the 'data cleaning' section (lines 370-540) and remove the need for having "temp" sheets (lines 60-130 and line 540).

    This should be very easy for any intermediate or advanced VBA user. Any one like to try?


    Please Login or Register  to view this content.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    A few things, not much:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    Thanks for the assistance JBeaucaire. However it doesn't remove the need for the 'temp1' & 'temp2' sheets.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    I use junk sheets all the time to massage data into submission then copy it to my main sheets. A fine method. I see no reason to rewrite a working macro simply because it does this.

  5. #5
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    Can you post what your data looks like after downloading from the website and what you want it to look like afterwards? From what I see you only need data from two cells? (Range("C2:D2") from temp2 sheet at the end.)
    Last edited by RHCPgergo; 02-11-2013 at 04:24 AM. Reason: I keep writing "you" instead of "your" -_-

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    Quote Originally Posted by RHCPgergo View Post
    From what I see you only need data from two cells? (Range("C2:D2") from temp2 sheet at the end.)
    Hello RHCPgergo,

    Thank you for your assistance.

    I don't actually require "temp2". A new sheet would do just as well. (I would like to do away with the two temp sheets and replace with an "add new sheet")

    All I want/require in the output is the following data:
    1. USD buy rate
    2. USD sell rate
    3. Currency (i.e. "USD")(This is a visual check to ensure the macro is picking up the correct currency).
    4. The date & time the rates were current at (This is included in the data downloaded from the website)

    The cell positions in the output are unimportant (they don't have to be C2:D2 etc). The only condition on this is that I need the buy & sell rate in two adjacent cells so I can easily copy/paste into another excel book.

    As you can see from the above - it is very flexible!

  7. #7
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    Here it is without adding additional worksheets.
    Please Login or Register  to view this content.
    I wonder why the webquery only works with "Public Sub". It refuses to work with a simple "Sub" procedure.

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    Quote Originally Posted by RHCPgergo View Post
    I wonder why the webquery only works with "Public Sub". It refuses to work with a simple "Sub" procedure.
    This is very close to what I was looking for! Thank you.

    Re: Public Sub: Hmmm. I hadn't noticed that it didn't work without it. I like to declare all functions & subs as Public if they are not private (Yes I know they are Public by default but I like to show it. I also insist on Option Explicit on all my modules! )

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Need a hand to clean up working code (External Data fetch foreign exchange rates)

    The code from RHCPgergo works for me so I will mark this thread as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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