Hello,
Dan, 2 cents okay? On the mult-row return, do you want to resize the range, incuding width? Also, you'll want to refer to specific sheets per the original quandary versus activesheet.
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> PushData2()
<SPAN style="color:green">'Via ADO</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> myXl <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>, myBk <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>, myRng <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> Rs <SPAN style="color:darkblue">As</SPAN> ADODB.Recordset
<SPAN style="color:darkblue">Dim</SPAN> sql <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, myVar <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, myCnt <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:green">'Create an Excel Instance</SPAN>
<SPAN style="color:darkblue">Set</SPAN> myXl = CreateObject("Excel.Application")
<SPAN style="color:green">'Set your Excel File to push the data too</SPAN>
<SPAN style="color:darkblue">Set</SPAN> myBk = myXl.Workbooks.Open("c:\temp\test5.xls")
<SPAN style="color:darkblue">With</SPAN> myBk.Sheets(1)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'Set your range to first available cell in Column A</SPAN></SPAN></SPAN>
<SPAN style="color:darkblue">Set</SPAN> myRng = .[a65536].End(3)(2)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'Stack an Sql Variable</SPAN></SPAN></SPAN>
myVar = "Field 2 Variable"
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'Stack your Sql in a String</SPAN></SPAN></SPAN>
sql = "Select F1, F2, F3 From tmpTable1 Where " & _
"F2=<SPAN style="color:green"><SPAN style="color:green">'" & myVar & "';"</SPAN></SPAN>
<SPAN style="color:darkblue">Set</SPAN> Rs = <SPAN style="color:darkblue">New</SPAN> ADODB.Recordset
<SPAN style="color:darkblue">With</SPAN> Rs
.ActiveConnection = CodeProject.Connection
.Source = sql
.<SPAN style="color:darkblue">Open</SPAN> , , adOpenStatic, adLockOptimistic
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:darkblue">If</SPAN> <SPAN style="color:darkblue">Not</SPAN> Rs.EOF <SPAN style="color:darkblue">Then</SPAN>
Rs.MoveLast: Rs.MoveFirst
<SPAN style="color:green"><SPAN style="color:green">'Rezise Excel Target Range Cell Array to</SPAN></SPAN>
<SPAN style="color:green"><SPAN style="color:green">'Accomodate Recordset Height/Width</SPAN></SPAN>
.Range(myRng, .Cells(Rs.RecordCount + myRng.Row, _
3)).CopyFromRecordset Rs
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
Rs.<SPAN style="color:darkblue">Close</SPAN>
<SPAN style="color:darkblue">Set</SPAN> Rs = Nothing: <SPAN style="color:darkblue">Set</SPAN> myRng = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:darkblue">With</SPAN> myBk.Sheets(2)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'Set your range to first available cell in Column A</SPAN></SPAN></SPAN>
<SPAN style="color:darkblue">Set</SPAN> myRng = .[a65536].End(3)(2)
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'Stack an Sql Variable</SPAN></SPAN></SPAN>
myVar = "Field 2 Variable"
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'Stack your Sql in a String</SPAN></SPAN></SPAN>
sql = "Select F1, F2, F3 From tmpTable2 Where " & _
"F2=<SPAN style="color:green"><SPAN style="color:green">'" & myVar & "';"</SPAN></SPAN>
<SPAN style="color:darkblue">Set</SPAN> Rs = <SPAN style="color:darkblue">New</SPAN> ADODB.Recordset
<SPAN style="color:darkblue">With</SPAN> Rs
.ActiveConnection = CodeProject.Connection
.Source = sql
.<SPAN style="color:darkblue">Open</SPAN> , , adOpenStatic, adLockOptimistic
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:darkblue">If</SPAN> <SPAN style="color:darkblue">Not</SPAN> Rs.EOF <SPAN style="color:darkblue">Then</SPAN>
Rs.MoveLast: Rs.MoveFirst
<SPAN style="color:green"><SPAN style="color:green">'Rezise Excel Target Range Cell Array to</SPAN></SPAN>
<SPAN style="color:green"><SPAN style="color:green">'Accomodate Recordset Height/Width</SPAN></SPAN>
.Range(myRng, .Cells(Rs.RecordCount + myRng.Row, _
3)).CopyFromRecordset Rs
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
Rs.<SPAN style="color:darkblue">Close</SPAN>
<SPAN style="color:darkblue">Set</SPAN> Rs = Nothing: <SPAN style="color:darkblue">Set</SPAN> myRng = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:green">'Close workbook, saving it, release WB object variable</SPAN>
myBk.<SPAN style="color:darkblue">Close</SPAN> True: <SPAN style="color:darkblue">Set</SPAN> myBk = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:green">'Close Excel instance, release application object variable</SPAN>
myXl.Quit: <SPAN style="color:darkblue">Set</SPAN> myXl = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
Hope one of these helps.