+ Reply to Thread
Results 1 to 9 of 9

Excel Macro to Rename each Worksheet based on Cell Values

  1. #1
    Registered User
    Join Date
    03-01-2017
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2007
    Posts
    77

    Excel Macro to Rename each Worksheet based on Cell Values

    Hi Excelforum Experts,

    I am currently using an excel macro template to consolidate multiple workbooks into one. However, I always spend much time renaming each worksheet of the workbook (I am now using the output of my excel macro template).

    In this regard, I would like to seek help for someone who could help me add additional VBA codes to the existing excel macro template I am currently using. I am attaching the excel macro template I am referring for you to add a function where it will automatically rename each worksheet of a workbook based on cell value. Below are the additional criteria of my desired output:

    1.) The additional VBA code should also run after clicking the "Automate" button on my excel macro template (see attached workbook).
    2.) Rename each worksheet based on "cell A4" of each worksheet. Cell A4 of each worksheet is Start Date: mm/dd/yyyy, the date may vary per worksheet.
    3.) The mm/dd/yyyy should be formatted to m/dd, thus, if cell A4 of Sheet1 is Start Date: 2/09/2017, Sheet1 will be renamed as 2.09. If cell A4 of Sheet2 is Start Date: 2/12/2017, Sheet2 will be renamed as 2.12. And so on.


    Let me know should you need clarifications. Thank you!

    Warmest regards,
    Arnel
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Just add something like this in your code:

    Please Login or Register  to view this content.
    Regards,
    Stephen

    If you feel someone has helped you please thank them and click on the star on their post to add reputation.
    Please ensure that you use code tags where relevant, and mark solved threads as solved.
    Most of all please be respectful and understanding of others.

  3. #3
    Registered User
    Join Date
    03-01-2017
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2007
    Posts
    77

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Hi Stephen,

    Thank you for your quick feedback. However, I am having an error per below code:

    ws.Name = Format(ws.Range("A4"), "M.DD")

    The worksheet name has a common name as Report, Report(2), Report(3),Report(4),Report(5), and so on. The common name is "Report".

    By the way, the content on cell A4 is shown below, but the date may vary per worksheet. Can we use the RIGHT function to get the date first before changing the format into m/dd?

    End Date: 2/7/2017

    Let me know should you need additional details.

    Thanks,
    Arnel

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Try this


    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-01-2017
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2007
    Posts
    77

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Hi mike7952,

    I tried using your code but no luck, I am having an error with the codes below:

    wbDst.Worksheets(wbDst.Worksheets.Count).Name = _
    Format(wsSrc.Range("A4").Value, "M.DD")

    I also tried the below code given by Stephen along with my existing codes but I still have an error.

    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    ws.Name = Format(CDate(Mid(Range("A4"), 11, 10)), "m.dd")
    Next ws

    I appreciate if you could please help me identify what went wrong and what needs to be fixed. I am attaching the workbook I am working for your reference. Thank you!

    Warmest regards,
    Arnel
    Attached Files Attached Files

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Try this

    Please Login or Register  to view this content.
    or with your other code your missing the ws. before the range. so your looping thru the worksheets but referncing the active sheet range a4, so its naming the sheets the same witch will cause your error.

    Please Login or Register  to view this content.
    Last edited by mike7952; 04-06-2017 at 11:02 PM.

  8. #8
    Registered User
    Join Date
    03-01-2017
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2007
    Posts
    77

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Hi All,

    I would like to inform you that after considering all your inputs, it works like magic! Thank you for sharing your expertise, I really appreciate it!

    Warmest regards,
    Arnel

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,519

    Re: Excel Macro to Rename each Worksheet based on Cell Values

    Thanks for the rep

+ 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] Using VBA to rename worksheet based on cell value
    By maciec in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-24-2016, 02:56 AM
  2. Rename worksheet based on cell value
    By sbeirne58 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2015, 12:11 PM
  3. Rename worksheet based on cell value
    By sbeirne58 in forum Excel General
    Replies: 1
    Last Post: 07-15-2015, 11:58 AM
  4. Rename worksheet based on cell with formula
    By JimmyT10 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2015, 08:44 AM
  5. 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
  6. [SOLVED] Rename worksheet tab based on cell value
    By Tritekfire in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-08-2014, 04:22 PM
  7. VBA to rename worksheet based on cell reference on another worksheet
    By Sandi99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2008, 01:46 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