Hello All,

I've written a (below)macro that pulls data from the sql server 2008 r2. My issue is when the user enters the Jobnumber for the first time excel puts data on the spreadsheet starting from "A1" cell. The issue here is, when the user runs the macro for the second time all the data is again put on spreadsheet starting from "A1" cell. How can I shift the previous entry down in the spreadsheet with the latest entry on top?

Here is my macro:

Sub Task()

Dim sqlstring As String


Dim connstring As String


Dim Strcode As String


Strcode = Trim(InputBox("Please enter a Job #", "Task history"))


sqlstring = "select distinct m.JobNumber , cast(m.ExpectedDate as DATE) 'Ship Date' ,m.CustLongName 'Customer' & _
             " from ArchiveJobHeader m  left join AuxiliaryInfoFile af (nolock) on af.jobnumber=m.jobnumber & _
             " where m.JobNumber = '" & Trim(Strcode) & "'" & _
             " order by 'Resulttime'"
connstring = "ODBC;DSN=SQLDSN;UID=test;PWD=test123"


 Dim thisQT As QueryTable


 Set thisQT = ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("a1", "a1000"))


 thisQT.BackgroundQuery = False


 thisQT.Sql = sqlstring




thisQT.Refresh


End Sub