VBA在先前粘贴的数据下粘贴下一组数据

时间:2016-08-02 15:39:59

标签: excel vba

以下代码用于从Access 2010表中复制标头并将其粘贴到excel 2010电子表格的特定选项卡和行上。目前,当它转到下一个要粘贴的2010表格标题时,它会在第一组标题的末尾粘贴它们。我试图将它粘贴到上一个粘贴数据下的行中。我做错了什么?

 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 

0 个答案:

没有答案