Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Delete Rows of Data in multiple Excel Sheets upon importing to Access

I'm importing data from multiple Excel sheets into an Access table.
Using the code below. However, the 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 to where the field name starts and
then start grabbing the data below 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. Before the import I call
the SQL CreateTable function to define the table 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Delete Rows of Data in multiple Excel Sheets upon importing to Acc

I would use something like this inserted into the top of the loop.

If Len(rsExcel(0)) = 0 then rsexcel.movenext



hth


" wrote:

I'm importing data from multiple Excel sheets into an Access table.
Using the code below. However, the 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 to where the field name starts and
then start grabbing the data below 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. Before the import I call
the SQL CreateTable function to define the table 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows of data in multiple sheets Yossy Excel Programming 14 October 26th 08 02:46 PM
Importing data from multiple Access queries JoeA2006 Excel Programming 1 August 29th 06 02:17 PM
Importing data from Access to Excel, but I need to vary the table from Access Liz L. Excel Programming 3 June 6th 06 02:12 AM
Delete rows in multiple sheets without loop? MTT727 Excel Programming 2 July 26th 05 03:07 PM
Delete Rows from multiple Sheets. drbobsled Excel Programming 3 April 7th 05 01:23 AM


All times are GMT +1. The time now is 07:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"