Tom
By far and away the best method would be to direct the SQL inherent within the query to pre-sort the data before it is imported, however, you can set up an event to monitor the query and respond once it has been performed:
1. In your workbook, open up the VBE and double-clcik on the ThisWorkbook icon. Place the following lines of code in the ThisWorkbook module that will open:
Public WithEvents qt As QueryTable
Private Sub Workbook_Open()
Set qt = Sheets(1).QueryTables(1)
End Sub
Private Sub qt_AfterRefresh(ByVal Success As Boolean)
qt.ResultRange.Sort key1:=qt.ResultRange.Cells(1, 2), order1:=xlAscending
End Sub
It will then sort the result data of the first querytable on the first sheet in the workbook after it has been updated, based on the second column in the data.
You will need to amend the "Sheets(1)" bit to ensure the correct query table-containing sheet is specified.
Richard
Bookmarks