T
tom_n_ape
I'm importing data from multiple Excel sheets into an Access table and
found that the code posted earlier by another user is a good starting
place for me. However, the spippet of code below starts copying data
on row 1 of the Excel sheet. Since the Excel sheets I am accessing
may not always have records starting on row 1, how can I modify the
code below to first scroll down and find which row column headings are
in and then start grabbing the data below that and then stop upon
reaching an empty row? All my Excel tables have the exact same column
headings; they just don't always start on row 1. So I already call
the SQL CreateTable function to define the before copying data from
the Excel sheet.
Thanks for any help you can provide...
' open a recordset on the Excel WorkSheet
Set rsExcel = dbExcel.OpenRecordset(tdf.Name)
rsExcel.MoveFirst
' loop throught all data in excel and stuff into access
Do
rsNewTbl.AddNew
For Each fld In tdf.Fields
rsNewTbl(fld.Name) = rsExcel(fld.Name)
Next
rsNewTbl.Update
rsExcel.MoveNext
' expect err 3021 and trap for it when we move beyond the
end of the data
If Len(rsExcel(0)) = 0 Then ' blank line also tosses us
out
Exit Do
End If
Loop
found that the code posted earlier by another user is a good starting
place for me. However, the spippet of code below starts copying data
on row 1 of the Excel sheet. Since the Excel sheets I am accessing
may not always have records starting on row 1, how can I modify the
code below to first scroll down and find which row column headings are
in and then start grabbing the data below that and then stop upon
reaching an empty row? All my Excel tables have the exact same column
headings; they just don't always start on row 1. So I already call
the SQL CreateTable function to define the before copying data from
the Excel sheet.
Thanks for any help you can provide...
' open a recordset on the Excel WorkSheet
Set rsExcel = dbExcel.OpenRecordset(tdf.Name)
rsExcel.MoveFirst
' loop throught all data in excel and stuff into access
Do
rsNewTbl.AddNew
For Each fld In tdf.Fields
rsNewTbl(fld.Name) = rsExcel(fld.Name)
Next
rsNewTbl.Update
rsExcel.MoveNext
' expect err 3021 and trap for it when we move beyond the
end of the data
If Len(rsExcel(0)) = 0 Then ' blank line also tosses us
out
Exit Do
End If
Loop