.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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,215,269
Messages
6,123,976
Members
449,138
Latest member
abdahsankhan

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