PC Review


Reply
Thread Tools Rate Thread

Delete Rows of Data in multiple Excel Sheets upon importing to Access

 
 
tom_n_ape@hotmail.com
Guest
Posts: n/a
 
      27th Oct 2008
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 With Quote
 
 
 
 
dmoney
Guest
Posts: n/a
 
      27th Oct 2008
I would use something like this inserted into the top of the loop.

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



hth


"(E-Mail Removed)" 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows of data in multiple sheets Yossy Microsoft Excel Programming 13 26th Oct 2008 02:46 PM
Importing multiple Excel sheets into Access =?Utf-8?B?YnJ1bW1t?= Microsoft Access External Data 1 6th Sep 2006 10:33 PM
Delete rows in multiple sheets without loop? MTT727 Microsoft Excel Programming 2 26th Jul 2005 03:07 PM
Delete Rows from multiple Sheets. =?Utf-8?B?ZHJib2JzbGVk?= Microsoft Excel Programming 3 7th Apr 2005 01:23 AM
Importing Excel Data from Multiple Files with Multiple Sheets Rafael Bradley Microsoft Access External Data 0 15th Jan 2004 10:50 PM


Features
 

Advertising
 

Newsgroups
 


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