+ Reply to Thread
Results 1 to 13 of 13

Save old data when web query refreshes

  1. #1
    Registered User
    Join Date
    12-14-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Save old data when web query refreshes

    Hello there,

    After reading one of your old posts - http://www.excelforum.com/excel-prog...refreshes.html - you've managed to help me out. I used your solution in post #11.



    Please Login or Register  to view this content.
    My question to you is; Instead of copying the old information to the right in the next column...is it possible to copy the old information below, to the next available row? So all information appears in the same column?

    I'm not sure how to write the code for that.

    Your help would be greatly appreciated.

    Thanks,

    Blake
    Last edited by BlakeCrossley; 12-20-2011 at 08:55 AM.

  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: Save old data when web query refreshes

    hi Blakely, welcome to the Forum. I'll take a look at your query, but you'll need to glance at the Forum Rules (link above) and edit your post above to follow. You need to add CODE tags around the code in that post the way I showed you previously.

    It's also demonstrated below in my signature. Go ahead and fix that while I look at your question. Thanks.
    _________________
    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
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save old data when web query refreshes

    Something like this:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Save old data when web query refreshes

    to prevent copying the webquery link:

    Please Login or Register  to view this content.



  5. #5
    Registered User
    Join Date
    12-14-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Save old data when web query refreshes

    I need to start over. What I am trying to do is keep a history of a certain stock. http://www.google.ca/finance/historical?q=TSE:FNV# So, this website keeps the history of the last 30 days or so. Tomorrow it will update with the most recent 30 days and the 31st day is gone forever. Using a web query, I was trying to combine a worksheet change event to copy the old data when the new day refreshed. Your solution in post #3 accomplished this. But I don't need all 30 days copied, just the newest information so I tried to combine it by using another macro to delete duplicate rows. I can't seem to get both ideas to work together. Your help would be greatly appreciated.

    Blake

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

    Re: Save old data when web query refreshes

    Let's see your workbook with the version of the macro you're currently using. Your workbook should clearly demonstrate the results you're trying to achieve manually mocked up if necessary.

  7. #7
    Registered User
    Join Date
    12-14-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Save old data when web query refreshes

    I've attached my example.
    Attached Files Attached Files

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

    Re: Save old data when web query refreshes

    This is how I would do that.

    1) Create a sheet called ARCHIVE and put your titles in A1:F1 to match your query titles
    2) Right-click the sheet tab of your QUERY sheet and select VIEW CODE
    3) Paste in this event macro:

    Please Login or Register  to view this content.
    4) Close the VBEditor and save the workbook as a macro-enabled workbook (*.xlsm)

    Now any time there is a change of anykind on the QUERY sheet, all the NEW data is checked and transferred to the Archive sheet to keep a permanent record. We do this as the data comes in rather than as it is erased.


    You can test this out by deleting a few rows on the the Archive sheet, then go back to the Query sheet and edit any cell off to the right, then check the Archive, the missing values will be back.
    Attached Files Attached Files

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Save old data when web query refreshes

    A more sophisticated approach using a class module to intercept the event Query_afterrefresh:
    See also the attachment

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    12-14-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Save old data when web query refreshes

    Thank you very much. That worked perfectly!

  11. #11
    Registered User
    Join Date
    02-09-2012
    Location
    Napoli
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Save old data when web query refreshes

    Good morning,

    I write from Italy and I very much appreciate what you have disclosed, and I would ask if you could help me to solve a problem.

    It 's interesting thread: When Web Query Save old data refreshes,

    I'd love to get the data in order to receive as a column and put down.

    That is the last figure should be the bottom.

    I hope I can help.

    greetings

    Carlito

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Save old data when web query refreshes

    Carlitos, welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  13. #13
    Registered User
    Join Date
    04-19-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Save old data when web query refreshes

    What am I doing wrong here? I have a single row query with two columns that I'm trying to copy to the archive sheet. It updates the Query Worksheet which then copies the data to the Archive worksheet but when I refresh every time it replaces the value in A2:B2 with the new refreshed data instead of keeping a history and writing the new values in the lines below. (A3, A4, etc). I've attached a copy of the workbook.
    Attached Files Attached Files

+ 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