Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:48:48+00:00 2026-06-13T15:48:48+00:00

I have the following code in my Excel VBA that copies data from a

  • 0

I have the following code in my Excel VBA that copies data from a table in SQL into Excel. This data is being inserted horizontally starting on cell C2, but I want it to be inserted vertically on column C.

Sheets("Control").Range("C2").CopyFromRecorset rsPubs

Where rsPubs is my ADO connection.

Basically, I just want this data transposed. What’s an efficient way of doing this?

This is how rsPubs is created (the connection works fine as I’m actually getting the data):

' Create a recordset object.
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset

With rsPubs
    ' Assign the Connection object.
    .ActiveConnection = cnPubs
    ' Extract the required records.
    .Open "SELECT * FROM Analytics.dbo.XBodoffFinalAllocation"
    ' Copy the records into cell B3 on Sheet1.
    Sheets("Control").Range("C2").CopyFromRecordset rsPubs
    ' Tidy up
    .Close
End With

cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:48:49+00:00Added an answer on June 13, 2026 at 3:48 pm

    I cannot test this currently, but you could:

    Sheets("Control").Range("C2").CopyFromRecorset rsPubs 'copy your data
    Sheets("Control").Range("C2").Copy 'copy the data into clipboard
    Sheets("Control").Range("C2").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, True, True
    

    Also you could use the Transpose Worksheetfunction – however, I don’t quite see a way right now to do this directly, expect your input data is transposed already.

    Here is a nice official example and further informations on this topic: How to transfer data from an ADO Recordset to Excel with automation

    Especially the "using GetRows" section.

    This should do:

    Dim resultset As Variant
    Dim result As Variant
    resultset = rsPubs.GetRows
    result = Application.WorksheetFunction.Transpose(resultset)
    Sheets("Control").Range("C2").Resize(UBound(result, 1), UBound(result, 2)) = result
    

    http://www.teachexcel.com/excel-help/excel-how-to.php?i=147811

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am have the following code for excel vba that will email a range
I have following code for inserting data into database using PDO. It inserts data
I'm a complete beginner to Excel VBA. The following is code I've written that
I have the following VBA code: mainFile = ActiveWorkbook.Name 'select all excel files in
I have the unfortunate task of having to import data from excel into a
I'm running Excel 2003. I have the following VBA code, corresponding to a simple
I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr,
I have VBA code that I wrote that creates an Excel Column Cluster chart
Hey fellas, I have the following VBA code. It gets the values from an
I have the following code to insert items into a MySQL database from an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.