.CopyfromRecordset row by row

justvba

New Member
Joined
Jan 6, 2017
Messages
41
Hi I want to paste 1 row at a time from a record set so that I can make it paste on a single row or some how transpose the record set results.

sub hi()

Dim cnnConnect As ADODB.Connection
Dim rstRecordset As ADODB.Recordset

Set cnnConnect = New ADODB.Connection

cnnConnect.Open "Provider=OraOLEDB.Oracle;" & _
"Data Source=query;" & _
"User ID=boo;Password=hey;"

Range("B1").Select

Do Until IsEmpty(Range("A" & ActiveCell.Row)) Or Trim(Range("A" & ActiveCell.Row)) = ""
someproduct = UCase(Trim(Range("A" & ActiveCell.Row)))

SQLSTATEMENT = "SELECT A.house, A.Signal, b.Car FROM " & _
"table.one A LEFT JOIN table.two b ON A.house = b.house " & _
"WHERE TRIM(A.make) IN ('" & someproduct & "')"

Set rstRecordset = New ADODB.Recordset
rstRecordset.Open _
Source:=" " & SQLSTATEMENT & " ", _
ActiveConnection:=cnnConnect, _
CursorType:=adOpenForwardOnly

ActiveCell.CopyFromRecordset rstRecordset
ActiveCell.Offset(1, 0).Select
Loop
Set cnnConnect = Nothing
Set rstRecordset = Nothing

END SUB
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top