+ Reply to Thread
Results 1 to 4 of 4

Macro to activate once web query has refreshed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-28-2009
    Location
    newcastle, uk
    MS-Off Ver
    Excel 2010
    Posts
    187

    Macro to activate once web query has refreshed

    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

  2. #2
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Macro to activate once web query has refreshed

    The easiest way would be to add the line below after your final END WITH.

    duplicateRemove

  3. #3
    Forum Contributor
    Join Date
    06-28-2009
    Location
    newcastle, uk
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: Macro to activate once web query has refreshed

    Thanks for the reply. I have tried to add this to the end of my macro but it does not seem to work. It lets me run the macro as normal, but none of the duplicate entries are removed.

    Gemma

  4. #4
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Macro to activate once web query has refreshed

    Would you attach the workbook so I can take a look and see what's happening?

+ 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