CSV import macro - Very Confused

bposaner

Board Regular
Joined
May 28, 2002
Messages
74
Very confused access newb and need help!! :oops:

I'm trying to write a macro to import csv files into a mdb.
I've searched the forum and found some examples, but im truly lost.

A sample of the csv file is below.
So currently I manually import the data with the following steps
1. 1st row contains field names.
2. skip first column (as its all blanks)
3. import all other cols, but with last column I import with a format date order of MDY.
4. import into existing DB

All help would be great
Many Thanks

Code:
,ÿþComputerName,ObjectName,PerformanceCounterName,PerformanceInstanceName,SampledValue,TimeSampled
,LIV-CER-WA-P01,LogicalDisk,% Disk Time,_Total,2.24748899462693,07-01-2007 00:05
,LIV-CER-WA-P01,LogicalDisk,% Disk Time,_Total,4.15209282684479,07-01-2007 00:09
,LIV-CER-WA-P01,LogicalDisk,% Disk Time,_Total,4.08122189087369,07-01-2007 00:15
,LIV-CER-WA-P01,LogicalDisk,% Disk Time,_Total,2.59458327199961,07-01-2007 00:20
,LIV-CER-WA-P01,LogicalDisk,% Disk Time,_Total,1.66944401777505,07-01-2007 00:24
,LIV-CER-WA-P01,LogicalDisk,% Disk Time,_Total,2.04877977885725,07-01-2007 00:29

There is about 200,000 rows in each file!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Have you considered looking into Linking/Import Tables with Access ?

"File" > "Get External Data" > "Import" or "Link Tables" from Excel.
 
Upvote 0
Confused :unsure:

I need to automatically get the data into an access db. Its far to big to put into Excel. I have around 200,000 rows of data for each day.

So the macro would run daily and import the data into an existing monthly db.
 
Upvote 0
If all the files are of the same format, then manually import one. It will invoke the import wizard where you tell it it is a comma delimited file with a header row and you can tell it the format of each column, and which column to ignore.

Then, just before the last step where it actually imports it to a table, click on the Advanced button and Save your Import Specification (give it some name). Now you can import files (manually, via macro or code) using this Import Specification.

If you go to the Macro section, start a new macro and select the TransferText option, you can enter the file name, specification, table, etc to import one table.

If you have multiple tables to import, if they always have the same name, just keep adding more TransferText commands. If they have different names, you will probably need to convert the macro to VBA and then write a loop.

To convert the macro to VBA, after you save one TransferText mancro, highlight the macro name and click on the Tools menu and select Macro | Convert Macros / to Visual Basic command. This will give you a good start on your VBA code. Then you just have to work on the loop and generalize the code a bit.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top