+ Reply to Thread
Results 1 to 6 of 6

Generate new name of file based on Original file name

  1. #1
    Registered User
    Join Date
    05-20-2020
    Location
    USA
    MS-Off Ver
    10
    Posts
    28

    Generate new name of file based on Original file name

    Hello,

    I have a list in excel of the files in folder. The filenames are of the form "1FT_DINRM_Bru_pt5GAL_TCL.wav". I want to rename the files with only numbers. The numbers are based as follows:

    2021-08-15_23-13-11.png

    For the filename given above, "1FT_DINRM_Bru_pt5GAL_TCL.wav", the output name to be generated will be "10003010500.wav". Another example for the file with an original name of "24FT10IN_Ane_Zm_4GAL_TCL_lclp.wav", the output file name will be "24100060240001.wav".

    Is there a way to accomplish this? If so, can you tell me how to go about doing this? I was thinking along the lines of XLOOKUP?

    For this use case, I would like to put the file names in one column, and the adjacent column will have the corresponding converted name.

    Any help will be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Generate new name of file based on Original file name

    You can do this by concatenating a few VLOOKUPs. It's a bit of a monster formula, but this should do it (put this in G18):
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The way it works is to successively lookup all the parts of the old filename between the _ characters, returning the correct numerical result from the lookup tables above, and then join them together using the concatenation operator (&). The various parts are found using LEFT for the first part then MIDs for the rest. SUBSTITUTE is used to find the appropriate _ characters (2nd, 3rd, etc). The last lookup is coupled with an error check to deal with old filenames which do or don't have _clp or _tclp after the TCL.

    Hope that does what you want.
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

  3. #3
    Registered User
    Join Date
    05-20-2020
    Location
    USA
    MS-Off Ver
    10
    Posts
    28

    Re: Generate new name of file based on Original file name

    THANK YOU! Your code works perfectly!

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Generate new name of file based on Original file name

    You're welcome. Thanks for replying to let me know and for marking the thread as Solved.

  5. #5
    Registered User
    Join Date
    05-20-2020
    Location
    USA
    MS-Off Ver
    10
    Posts
    28

    Re: Generate new name of file based on Original file name

    Just wanted to tell you once again...that your code have been such a life saver for me. I sincerely appreciate you taking the time out to help me out the way you did. I really sincerely appreciate it! Cheers!

  6. #6
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Generate new name of file based on Original file name

    You're very welcome. It's good to know that it's still working for you, without any special cases causing problems.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 8
    Last Post: 12-02-2019, 03:42 PM
  2. [SOLVED] Need VBA to create new Workbook and name it based on cell value in original file
    By YukonSoDank in forum Excel Programming / VBA / Macros
    Replies: 65
    Last Post: 06-08-2019, 02:47 PM
  3. Replies: 1
    Last Post: 04-26-2018, 11:44 AM
  4. How to check Last Modified Date on Temp File and compare it to original/parent file?
    By CaffeinatedCoder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2016, 07:42 PM
  5. VBA that works perfectly in one file errors out in a new file based off the original!
    By carthesis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2016, 07:24 AM
  6. Delete a file that has just been saved and open original file or vice versa.
    By SHB19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2015, 07:48 AM
  7. Script/macro to save a copy as tab delimited text file and then close original file
    By Merlin803 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2015, 01:34 PM

Tags for this Thread

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