+ Reply to Thread
Results 1 to 22 of 22

Bulk rename excel files based on values of two different cells

  1. #1
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Bulk rename excel files based on values of two different cells

    Hello everybody

    I need your help in this small problem. I tried to use/modify many scripts I found on the internet but none of them does the job.

    I have about 500 xlsx files in one single directory (it is a network path), all saved with Excel 2010.

    I would like to have a bulk rename of all of them using their values in cell C3 and cell C10 placed in Sheet1

    For example... if one of the 500 files contains the text "Paul Smith" in C3 and "Kyle White" in cell C10, then the file will be renamed in "Paul Smith x Kyle White.xlsx"
    And so on with all the other xlsx files in that directory
    I do not need and user input interface.. just run the macro and voila'... all files renamed with their C3 and C10 values.

    The operation should be made using a script placed in a macro enabled excel file that is saved in that directory.

    This will save me a lot of time !

    Thanks in advance for your kind help
    Last edited by Czarny; 01-20-2015 at 04:36 AM. Reason: Problem solved, thanks.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    You can link closed workbook via formula, so we can use vba to extract the data from C3 and C10.
    So the code will loop through each workbook and enter the formula in your code workbook
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    It will then rename the workbook according to the formula value.
    Here is the complete code.

    Please Login or Register  to view this content.
    See attched.

    Be sure to edit the code to your folder addresses.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    Many thanks for your fast reply.

    I modified the path name on your file and run the script.

    After the first file is checked and its name is written in the code workbook, I get a runtime error 100 Application-Defined or object-defined error and the debugger highlights me the following line:

    a1 = "=[" & MyFile & "]Sheet1!R3C3&""-x-""&[" & MyFile & "]Sheet1!R10C3"

    Surely I did something wrong, but I cannot figure out where

    P.S: I would like to attach one of those files as an example but the Forum is a bit tricky and I cannot
    Last edited by Czarny; 01-15-2015 at 07:42 AM. Reason: tried to add excel file

  4. #4
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    123456.xlsx

    This is the file.. finally managed to upload it

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    Did it work the 1st time?

  7. #7
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    Quote Originally Posted by davesexcel View Post
    Did it work the 1st time?
    Nope.. I had to switch to basic upload to attach the file.

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    Jees, I was talking about the code.

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    Anyway the code worked for me even in your attached example.

  10. #10
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    Thanks for double checking.. I am still having the problem I mentioned above 'runtime error 1004' and the debugger highlights me the following line:

    a1 = "=[" & MyFile & "]Sheet1!R3C3&""-x-""&[" & MyFile & "]Sheet1!R10C3"

    P.S. I am testing it on a local Excel 2013 since the Excel 2010 environment where it will be used is currently offline.

  11. #11
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    double post due to forum timeout
    Last edited by Czarny; 01-15-2015 at 09:12 AM. Reason: double post due to forum timeout

  12. #12
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    You didn't answer the question, did it run the first time?

  13. #13
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    Sorry. No, it did not run the first time and it doesn't run yet on other PCs.

  14. #14
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    When you hover over A1 in the code what does it say?

  15. #15
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    After the script is executed and the above error is displayed, in the workbook code I have:
    Cell A1 empty (blank), while Cell A2 contains the path and the original name of the first excel file in the given directory. All other cells are empty.

  16. #16
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    If I run it the first time it works, then run it a second time it fails, I need to rename the sheets again, before using the formula code.

    I would click reverse button to, rename the sheets, then click the rename button, to rename as the sheets in the cells you referred to.

    See how the attached works for you.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    First of all I would like to thank you for the time you are spending on this.

    I tried this new solution on 610 Excel files to be renamed

    I pressed 'reverse'
    Cells from A2 to A611 are now showing original path and name of the Excel file found in the directory
    Cells B2 to B611 are showing a progressive number from 1 to 610
    I pressed 'rename'.. the scripts works but after few seconds it stops with a 'Run time error 58, file already exists'
    It seems that the scripts itself is working correctly because half of the files were renamed correctly, but it stops if the cells extracted have the same name of one file already present in the directory. This might happen in case of identical names in cell C3 and empty field in cell C10.
    Is there a way to rename automatically identical files with a progressive extension at the end (let's say PAT SMITH-x-.xlsx and PAT SMITH-x-1.xlsx) without stopping the script with an error?
    Again.. thank you very much!

  18. #18
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    I'll have to Check in later,

    But maybe look at this for now.

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    Thanks for your quick reply.
    The script now does the job correctly. All the files are renamed according to the value of the cells and, if we have a duplicate, it is not a problem (I tried it also with 4 files with same contents, and the scripts rename everything 1,2,3...). Even if I run it once more in the same folder, with the files just renamed by the script, it does the job again.
    So, for me the script is ok but... when it ends, it gives me the same exact error it was giving me on the first try (Run Time Error 1004). It is not a real problem, since the code works, but the last error is a bit annoying.
    Please tell me if I have to sign this thread as solved or not.
    Thanks again!

    P.S. I forgot to add one more thing: since the names in cell C3 and C10 can be both uppercase and lowercase, is it possible to convert everything to uppercase while renaming the files?
    Last edited by Czarny; 01-19-2015 at 10:16 AM. Reason: one more step if possilbe

  20. #20
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Bulk rename excel files based on values of two different cells

    I guess we can put a resume next if there is an error, at least it won't go to the degugger then
    Please Login or Register  to view this content.
    Last edited by davesexcel; 01-20-2015 at 02:05 AM.

  21. #21
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    Great! Once more, thank you very much. You saved me a lot of time.
    I wish you all the best!

  22. #22
    Registered User
    Join Date
    02-25-2014
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Bulk rename excel files based on values of two different cells

    I thought it was everything fine but there is just one small problem.
    I finally run the script on the production folder containing 650 Excel files.
    All steps require about 5 minutes to finish. Server is not very fast, but this is not the issue.
    There is a strange behavior only on one random file. Let me explain
    The first step is performed and all lines in the work code are populated with the path and file names then all files in the directory are named from 1.xlsx to 650.xlsx
    Second step renames all numbered files with proper name. After this process is finished I always have one file named 0.xlsx.
    I run the script 5 times and the file named 0.xlsx is always the one in cell A3 after the first step (cell B3 shows progressive number '2').
    After second step, this file temporarily named 2.xlsx is renamed to 0.xlsx and this name remains and is not changed correctly.
    Please find attached a screen shot of the problem

    steps.png

    Do you have any idea? Thanks once more

+ 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. Can a macro rename Excel files based on a cell's contents?
    By chrisd2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2014, 09:51 AM
  2. [SOLVED] Rename tabs based on values entered in specific cells
    By rshnkmr39 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2013, 06:55 AM
  3. Rename Excel files based on cell contents
    By remco_t in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2012, 06:10 PM
  4. Rename files based on excel worksheet list
    By badgeradrian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2009, 05:52 PM
  5. [SOLVED] Rename Worksheets Based on Values in cells
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-31-2005, 03:05 AM

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