To implement the BeforeRefresh and AfterRefresh solution, proceed as follows:
1. Add a class module (Class1) and put in the following code:
Public WithEvents qt As QueryTable
Dim C3BeforeRefresh As Variant
Private Sub qt_BeforeRefresh(Cancel As Boolean)
C3BeforeRefresh = Worksheets("Live").Range("C3").Value
End Sub
Private Sub qt_AfterRefresh(ByVal Success As Boolean)
With Worksheets("Live")
If .Range("C3").Value <> C3BeforeRefresh Then
.Range("C4").Insert Shift:=xlDown
.Range("C4").Value = C3BeforeRefresh
End If
End With
End Sub
2. Add the following code at the top of your existing Module2 module:
Dim Query As New Class1
Sub Initialise_Query()
Set Query.qt = ThisWorkbook.Sheets("Live").QueryTables(1)
End Sub
3. Run Initialise_Query once. You could automate this by calling it from the Workbook_Open event in the ThisWorkbook module, like this:
Private Sub Workbook_Open()
Initialise_Query
End Sub
A simpler solution is to add a second sheet and have the Worksheet_Change event on the Live sheet update that second sheet if the C3 cells are different.
Bookmarks