+ Reply to Thread
Results 1 to 7 of 7

Adding portion of filename to field

  1. #1
    Registered User
    Join Date
    10-05-2010
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Question Adding portion of filename to field

    Hi Everyone,

    I'm hoping someone out there who has programming skills might be able to help someone who has no programming skills and frankly isn't wired to do it! Me!

    I can't imagine this would be easy at all - but here's what I'm hoping to have done.

    I have about 2500 csv files. For each csv file I'd like to take a portion of the name and add it to a new field for each record in that csv. The idea is the name has a unique identifier in it and if I can get that unique identifier in a field I can append all these csv files into one yet still know where each record came from. There is at the moment no unique Identifier in the records.

    Each csv name is formatted essentially the same way - here it is. Stands_GM_A4535625344_all_returns_elevation_stats.csv The A4535625344" portion of the name will always have a letter at the start but the number of numbers after that may be different (I think 8-11).

    So, I'd like to take the "A4535625344" portion of the name of a csv and enter it into a new field in the same csv that the name came from.

    I couldn't write this code to save my life so any help would be great!

    Thanks!

    Sue:
    Last edited by suzannemonette; 11-04-2010 at 10:50 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding portion of filename to field

    Rather than edit the CSV itself, I already have a macro that inserts the CSV fieldname into col A as multiple CSVs are imported into a single master sheet. Like so:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 11-04-2010 at 11:01 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding portion of filename to field

    Here's a second routine that can be added to get just the numeric portion of the name string and put it into the col A values.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-05-2010
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Adding portion of filename to field

    Hi!

    Man people that can code are so great! My first question is, the code that pulls out the number in a file name, will that work on my filename since the unique identifier has a letter in front of the number? The letter is part of what makes it unique (I think - not much documentation on how they named things) so it would be a huge bonus to keep it.

    Sue

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding portion of filename to field

    Is the string you want always the 3rd part? That might be easier...

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Adding portion of filename to field

    Maybe just change this one line in the Function:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-05-2010
    Location
    Nova Scotia, Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Adding portion of filename to field

    Quote Originally Posted by JBeaucaire View Post
    Maybe just change this one line in the Function:

    Please Login or Register  to view this content.
    Thanks! I'll give it a try and see how it goes.

    Sue

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1