Import excel records into access based on column value

时间:2016-07-11 22:42:18

标签: ms-access access-vba

I am a newbie with access and I am trying to import records into several tables from an excel file. Each row in excel has different number of columns, but the good thing is column A is able to help me to identify what records need to go to my different tables.

Sample table

As you can see in the picture, Row 1 Column A has the value of "H", which would indicate that this record needs to go to the "H" table. Then the next few rows have a value of "R" in Column A which indicates that these records should go to the "R" table, and so on and so forth. However, the number of records to be imported into each table will vary all the time. Like the sample above rows 2 through 10 belong to the table R, but the next import may have only 5 or 20 records.

Currently I am using a temporary table and using an append query for each table but I am wondering if there is an easier way via VBA or other method that could be faster and more efficient.

Thanks!

1 个答案:

答案 0 :(得分:0)

你现在这样做的方式可能是最好的方法。另一种方法是分两步完成:

1)拆分A列,然后解析到不同的工作表(或不同的工作簿)。

http://www.rondebruin.nl/win/s3/win006.htm

2)将这些不同的工作表(或工作簿)加载到不同的表中。

http://www.accessmvp.com/KDSnell/EXCEL_Import.htm#ImpAllWktsSepTbl

http://www.accessmvp.com/KDSnell/EXCEL_Import.htm#ImpFldWrkFiles