Solved

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

Posted on 2016-08-17
11
15 Views
Last Modified: 2016-10-03
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.
MDD-Image.PNG
0
Comment
Question by:gracie1972
11 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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.
0
 

Author Comment

by:gracie1972
Comment Utility
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?
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 500 total points
Comment Utility
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.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
Please post a representative sample data set
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
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])

/gustav
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 500 total points
Comment Utility
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.
Is
1,234,888,
"1,234", 888
OR
1, "234,888"
?
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
@gracie1972

Where's the sample data file?
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
@aikimark, Why do you need a sample data file?

@Gracie, Next time please start a new question so you can allocate points fairly.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
Why do you need a sample data file?
@Pat,
There might be a solution that the other experts haven't offered.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now