+ Reply to Thread
Results 1 to 12 of 12

Rename files based on Cell Content

  1. #1
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Rename files based on Cell Content

    I'm creating new 2017 OSHA Logs for 100+ branches. I have one macro that creates the needed workbooks, and another one that opens each workbook that was just created and populates the needed information into the worksheets, and then finally the macro saves and closes the workbook. I would like to add additional code in the second macro (if possible) that will rename each file based on the branch's name (which would be in cell "AE20" of the 300A Summary sheet...please see attached). Here are the two macros:

    FIRST
    Please Login or Register  to view this content.
    SECOND

    Please Login or Register  to view this content.
    Any guidance you could provide would be appreciated. Thank you for your consideration. PS: I am now using Excel 2016.
    Attached Files Attached Files
    Last edited by JPDutch; 01-05-2018 at 08:54 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Rename files based on Cell Content

    Here is some untested air code that may be what you are looking for

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Rename files based on Cell Content

    Since workbook is opened in same dir as 300A workbook.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 01-05-2018 at 09:31 PM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    Bakerman2, thank you, but it's hanging up on

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    Alansidman, I wasn't able to get this to work...I'd like to avoid the input box and just have it flow automatically.

  6. #6
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    Thank you Alansidman and Bakerman2. As I looked through both of your replies, I thought of this:

    Please Login or Register  to view this content.
    It doesn't actually rename the workbooks, but it does create new ones that are named after the branches. If there's a way to make this rename the workbooks created in the first macro, I'm still interested.

    Thanks again,

    JPDutch

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Rename files based on Cell Content

    Since you know you need 5 copies you probably also know the branch names in advance.
    Why not name your files properly on creation ?

  8. #8
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    My apologies for taking so long to respond. I actually have 217 branches, which number ebbs and flows as we close one branch and open several others over the course of a year; hence the names keep changing. I'm hoping to find a simple way to manage all of the names.

    I keep the branch list up-to-date through the year, and at the end of the year the macros are set to select the branch name, address, and so forth, but then I'd like to be able to save the files based on the names. I only use 5 to test the macro for the moment, and once I know everything works, I change 5 to 217. Hope that makes sense.

    Thank you,
    JPDutch

  9. #9
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    I don't know if anyone is reading this deep into the thread, but I'm hoping someone can help me with this. As mentioned earlier, I used this code to create and name files, and it was working well. Then I noticed that it skipped files...files based on numbers (if you could look at the original post under the "First" and "Second" macros, you'll see that the first one creates a file which is numbered 1-5...well now it's up to 218...but the problem is that it skipped files 21 through 99, and I can't figure out why. (Oh, you'll note that I changed the years from 2016 to 2017.)

    Please Login or Register  to view this content.
    Your advice would be greatly appreciated.

    Thank you,

    JPDutch

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Rename files based on Cell Content

    JP,

    You have an updated list of branches so the way I'd do it is to loop through that list creating a workbook, do your stuff with the second code and name it to the list name in the loop.

    That way you do it all in 1 go and you don't need to create, reopen and save again under a different name.

  11. #11
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    Bakerman2, Thank you; the only problem is that I'm not good at VBA. I've tried to figure this out, but to no avail. Could you give me an example? and would I place the code in that part of the second macro where I have the red wording? I do have the list of branches established in one of the worksheets, but I'm not sure how to reference the list or create the loop in VBA. Any help you could offer would be very much appreciated!

    Thank you again,

    JP

  12. #12
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Rename files based on Cell Content

    I've not been completely successful with the code I submitted earlier in this thread. I'm trying to develop one macro (as suggested by Bakerman2) that will create a workbook (an OSHA Log), fill in the data, save the workbook based on the branch's name (there are over 200 branches), close the workbook, and go to the next OSHA Log. The code I managed to develop (still a two-step process) skips a number of workbooks, thus requiring me to finish the remaining 40 OSHA Logs manually. Any ideas will be appreciated.

    Thank you for considering this post,

    JPDutch

+ 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. [SOLVED] Macro to rename cell content based on the starting character until found same character
    By oeyandyprawira in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-19-2015, 09:36 AM
  2. 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
  3. Rename cell based on file name for multiple files
    By lmolokin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2012, 05:49 PM
  4. [SOLVED] Export as pdf with different files based on cell content
    By wing_nut in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-06-2012, 07:59 PM
  5. 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
  6. Macro to open files based on cell content
    By livinglegend629 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-16-2011, 03:41 PM
  7. Rename worksheet based on content in Cell C3
    By jieyi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-09-2009, 12:37 PM

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