VBA to paste next set of data under previous pasted data

kthorson16

New Member
Joined
Sep 3, 2015
Messages
27
Below is the following code I am using to copy the headers from an access 2010 table and paste them on a specific tab and row of an excel 2010 spreadsheet. Currently when it goes to the next access 2010 table headers to paste, it is pasting them at the end of the first set of headers. I am trying to get it to paste in the row under the previous pasted data. What am I doing wrong?

Sub OpenTable()


Dim rs As Object
Dim X As Integer
Dim Conn As String
Dim strTable As String
Dim rngDbPath As Range
Dim cn As Object
Dim i As Integer
Dim Coll As New Collection
Dim rDirList As Range

Set rs = CreateObject("ADODB.Recordset")

For Each rngDbPath In Sheets("DRG").Range("I6:I99")

strTable = "Rx"
Conn = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source=" & rngDbPath.Value

rs.Open Source:=strTable, ActiveConnection:=Conn, CursorType:=1, LockType:=3

X = X + 1
For i = 0 To rs.Fields.Count - 1
Coll.Add rs.Fields(i).Name
Next i


For i = 1 To Coll.Count
Sheet = "COSMOS New Deals Database"
Cells(25, i) = Coll(i)
Next i

rs.Close

Next

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Would changing
Code:
Cells(25, i) = Coll(i)
to
Code:
Cells(X, i) = Coll(i)
give you the results you want?
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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