Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 35
  • Last Modified:

Import excel CSV into Access at Row 2 and only columns A:L

I am sure there is an easy way to do this.  I have an excel spreadsheet that gets dropped each Monday.  

I need to automate this file to import into access and dump into our SQL tables.  Right now we have to manually delete the first 2 rows (Header and a blank line).  The file names are at row 3 and we only need columns A:L.   What code can I write that is the easiest way to do this?  

I have a screen shot of the actual file after I opened it in excel.
3 Solutions
You can link to the table as is.  Create a query that selects the columns you want - they won't be named correctly but that doesn't matter.  Change the query to an append query.  Then, since the column names don't match, you will have to manually map each column.  So F1 will append to KeyYearRDD (I hope you are not actually using column names with special characters and embedded spaces in your SQL Server database).

Then add criteria that selects only rows where column F1 is numeric.  That will pick up only the rows with a valid year and ignore the others.
gracie1972Author Commented:
My next question is that the data is a common delimited file and there is also numbers with commas separated by commas, is there any way to get around this barrier?
Numbers containing comas are text rather than numeric.  In the standard csv format, text fields are enclosed in double quotes.  So -
"RecID", "FirstName", "LastName", "Phone", "Fee", "PaidDT"
34567,"Pat","Hartman","2035511212",45.16, 8/17/2016

Another alternative is to use tabs as the delimiter rather than comas but that is not standard so you will have to create an import spec to import the file.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Please post a representative sample data set
Gustav BrockCIOCommented:
There are no commas on your sample picture. Integers only.

However, if you have comma as the decimal separator, you can simply use CCur to convert:

    NetSales: CCur([F8])

You can't convert the commas after the fact since they end up causing additional columns when the file is imported so there are no commas actually in the data.  Clearly, the person who created the file didn't understand how csv works and that the commas would cause bogus fields when the file was imported by a program that assumed conforming format.

If you can't get the originator to produce a valid format csv using either of the two formats I suggested or by eliminating the embedded commas, you will have to import the file using the VBA file I/O method and parse the record yourself.

You could use the split function and then count the resulting items in the array.  If the count = the number of expected columns, the data did not include a comma and you can just take each item and place it directly in field.  If the item count exceeds the number of columns, then it depends on how many columns could contain a comma.  If multiple columns could contain a comma and the fields surrounding the bad data are numeric, I'm not sure how you will sort this out.
"1,234", 888
1, "234,888"

Where's the sample data file?
@aikimark, Why do you need a sample data file?

@Gracie, Next time please start a new question so you can allocate points fairly.
Why do you need a sample data file?
There might be a solution that the other experts haven't offered.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now