hello all,
I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with.
In a workbook at the start of the year (january) i will have 4 sheets and these sheets will keep increasing to 12 when the month is december. so i want is, sheet 1 (named abc) should go into table 1 (named abc), sheet 2 (named def)should go into table 2 (named def), sheet 3 (named xyz) should go into table 3 (named xyz). then sheet 4 through the next sheets till sheet 12 (named balance1, balance2, abalance3...so on till balance12) should all go into one table 'table4' (named balance) and all these sheets should keep appending starting from 1 then 2 all the way to 12.
I am able to put one sheet into one table and below is the code....i need help with the other part of my requirement
[CODE=vb]
Dim cn As ADODB.Connectio n
Dim oRs As New ADODB.Recordset
Dim cnAccess As ADODB.Connectio n
Dim rsAccess As New ADODB.Recordset
' Open Excel Connection
Set cn = New ADODB.Connectio n
With cn
.Provider = "Microsoft.Jet. OLEDB.4.0"
.ConnectionStri ng = "Data Source=C:\Test. xls;" & _
"Extended Properties=Exce l 8.0;"
.Open
End With
' Open Access Connection
Set cnAccess = New ADODB.Connectio n
With cnAccess
.Provider = "Microsoft.Jet. OLEDB.4.0"
.ConnectionStri ng = "Data Source=C:\Docum ents and Settings\krishn am\Desktop\Inte rcompany Consolidation.m db;"
.Open
End With
' Load ADO Recordset with Excel Sheet1Data
oRs.Open "Select * from [abc$]", cn, adOpenStatic
MsgBox oRs.RecordCount
' Load ADO Recordset with Access Data
rsAccess.Open "select * from tbl_abc", cnAccess, adOpenStatic, adLockOptimisti c
MsgBox rsAccess.Record Count
'Synchronize Recordsets and Batch Update
Do While Not (oRs.EOF)
rsAccess.AddNew
For i = 0 To 11 -----11 columns in table 1
rsAccess.Fields (i).Value = oRs.Fields(i).V alue
Next
rsAccess.Update
oRs.MoveNext
Loop
End Sub
[/CODE]
please help me so that i can move forward...
I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with.
In a workbook at the start of the year (january) i will have 4 sheets and these sheets will keep increasing to 12 when the month is december. so i want is, sheet 1 (named abc) should go into table 1 (named abc), sheet 2 (named def)should go into table 2 (named def), sheet 3 (named xyz) should go into table 3 (named xyz). then sheet 4 through the next sheets till sheet 12 (named balance1, balance2, abalance3...so on till balance12) should all go into one table 'table4' (named balance) and all these sheets should keep appending starting from 1 then 2 all the way to 12.
I am able to put one sheet into one table and below is the code....i need help with the other part of my requirement
[CODE=vb]
Dim cn As ADODB.Connectio n
Dim oRs As New ADODB.Recordset
Dim cnAccess As ADODB.Connectio n
Dim rsAccess As New ADODB.Recordset
' Open Excel Connection
Set cn = New ADODB.Connectio n
With cn
.Provider = "Microsoft.Jet. OLEDB.4.0"
.ConnectionStri ng = "Data Source=C:\Test. xls;" & _
"Extended Properties=Exce l 8.0;"
.Open
End With
' Open Access Connection
Set cnAccess = New ADODB.Connectio n
With cnAccess
.Provider = "Microsoft.Jet. OLEDB.4.0"
.ConnectionStri ng = "Data Source=C:\Docum ents and Settings\krishn am\Desktop\Inte rcompany Consolidation.m db;"
.Open
End With
' Load ADO Recordset with Excel Sheet1Data
oRs.Open "Select * from [abc$]", cn, adOpenStatic
MsgBox oRs.RecordCount
' Load ADO Recordset with Access Data
rsAccess.Open "select * from tbl_abc", cnAccess, adOpenStatic, adLockOptimisti c
MsgBox rsAccess.Record Count
'Synchronize Recordsets and Batch Update
Do While Not (oRs.EOF)
rsAccess.AddNew
For i = 0 To 11 -----11 columns in table 1
rsAccess.Fields (i).Value = oRs.Fields(i).V alue
Next
rsAccess.Update
oRs.MoveNext
Loop
End Sub
[/CODE]
please help me so that i can move forward...
Comment