Jason
Jason

Reputation: 506

Can I copy only one row/field from a recordset to an excel column

Is there a way to copy the values from a single column of a recordset to a column in Excel without have to use a loop? I tried the following to copy a single column:

    Sheet4.Range("Complete").CopyFromRecordset rsEDW.Fields(3)

But that did not work.

Upvotes: 1

Views: 6803

Answers (1)

Matt
Matt

Reputation: 510

EDIT: It looks a though you can copy just one column without a loop with the max column reference.

https://msdn.microsoft.com/en-us/library/office/aa223845%28v=office.11%29.aspx

I don't think there is anyway to do it without looping. You would have to loop through the record set and make each column a field from the record set.

With rs
    Do Until .EOF
        ActiveSheet.Range("A" & lastRow).CopyFromRecordset rsEDW.Fields(3)
        ActiveSheet.Range("B" & lastRow).CopyFromRecordset rsEDW.Fields(4)
.MoveNext
lastRow = lastRow + 1
Loop
End With

Upvotes: 3

Related Questions