+ Reply to Thread
Results 1 to 13 of 13

Save old data when web query refreshes

Hybrid View

  1. #1
    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:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range, MyRNG As Range, DateFIND As Range
    
    On Error Resume Next
    Set MyRNG = Range("A:A").SpecialCells(xlConstants, xlNumbers)
    If MyRNG Is Nothing Then Exit Sub
    
    With Sheets("Archive")
        For Each cell In MyRNG
            Set DateFIND = .Range("A:A").Find(Format(cell, cell.NumberFormat), LookIn:=xlValues, LookAt:=xlWhole)
            If DateFIND Is Nothing Then
                cell.Resize(, 6).Copy .Range("A" & .Rows.Count).End(xlUp).Offset(1)
            Else
                Set DateFIND = Nothing
            End If
        Next cell
        .Range("A:F").Sort Key1:=.Range("A2"), Order1:=xlDescending, Header:=xlYes
    End With
    
    End Sub
    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
    _________________
    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!)

+ 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