Look at the QueryTable BeforeRefresh and AfterRefresh events.
Thanks for the help. Really appreciate it. I googled the afterrefresh events. I know its the perfect solution. But it contains VB which I am ignorant about.
I gathered some code which works fine. I am trying to fire it through an IF function if possible. Something like if Cell C3 <> C4 then the macro runs, but it isn't happening. If I only knew why, I would try it through a formula coz VB is something out of my reach completely.
Thanks a lot for your help.
To implement the BeforeRefresh and AfterRefresh solution, proceed as follows:
1. Add a class module (Class1) and put in the following code:
2. Add the following code at the top of your existing Module2 module:![]()
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
3. Run Initialise_Query once. You could automate this by calling it from the Workbook_Open event in the ThisWorkbook module, like this:![]()
Dim Query As New Class1 Sub Initialise_Query() Set Query.qt = ThisWorkbook.Sheets("Live").QueryTables(1) 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.![]()
Private Sub Workbook_Open() Initialise_Query End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks