Append a column during import of file?

Montez659

Well-known Member
Joined
May 4, 2005
Messages
918
I am looking at moving something like 144 excel files into Access to do some analysis on them. Each of the groups of files is broken up into a specific year, so 16 of them are 2005, 16 are from 2006, etc. However, none of them actually have the year included in any columns in the file.

There might be some overlap with codes and such, so I want my PK to be from these codes and the year. Is there any way that I can get the data to append a column of the year while importing, so that I don't have to manually add a column to the 144 files?

If there is no Access answer to this, might there be an Excel answer? If so, I'll post there. TIA
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I don't think that is going to do what they want, as that would be "hard-coded" the prefix in the table ahead of time.

I had have situations like this some years ago, where I needed to capture the file name of each file I imported in a field in the table, since I was importing all the data into one table, but needed a way to identify which file each record came from. So here was the approach that I took (that may work for you):
1. Create a new field at the end of your table (maybe called "myFileName")
2. Create VBA code that loops through all files, and imports them
3. Within each loop, capture the name of the file you are importing in a variable
4. Then create an Update Query that filters on all records where the "myFileName" variable is blank, and update the "myFileName" field value to the name of the file

So, within the loop, it will Import each file, them immediately populate this new field for each record just imported. I am thinking that you could do something similar for each year, provided that the year number is either part of the file or folder name.
 
Last edited:
Upvote 0
Thanks Joe, sounds like an excellent idea! All the file names are the same across all the years, but the folder does contain the year so that would help me distinguish it. In addition to solving my issue, you also pointed me toward a more efficient way of doing the actual import via vba.

Thanks again!
 
Upvote 0
You are welcome!
Glad I was able to help!:)
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

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