Hi all
I have managed to use macros provided in http://www.excelforum.com/excel-prog...refreshes.html to get my web query to work correctly. The only problem I have is the archive page duplicates previous data. I have found an easy solution for this in the data ribbon, using remove duplicates.
I have set up a macro to remove duplicates for me, which works fine, but I was wondering is there any way of triggering the macro each time the web query refreshes, so I dont have to manually run the macro every time. I have tried seaching the web but cannot find the solution I am looking for.
The code used for the web query to transfer to the archive tab is as follows:
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(, 16).Copy .Range("A" & .Rows.Count).End(xlUp).Offset(1)
Else
Set DateFIND = Nothing
End If
Next cell
.Range("A:s").Sort Key1:=.Range("b3"), Order1:=xlAscending, Header:=xlYes
End With
End Sub
and the duplicate macro is as follows:
Sub duplicateRemove()
'
' duplicateRemove Macro
'
'
Range("A2:Q2").Select
ActiveSheet.Range("$A$1:$Q$10000").RemoveDuplicates Columns:=Array(2, 3, 4, 5, 6, 7, 8 _
, 9, 10, 11, 12, 13, 14, 15, 16, 17), Header:=xlYes
ActiveWindow.SmallScroll Down:=18
End Sub
Thanks in advance
Gemma
Bookmarks