+ Reply to Thread
Results 1 to 8 of 8

Dynamically change multiple sheet names based upon a cell's value

  1. #1
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Dynamically change multiple sheet names based upon a cell's value

    Hi,

    I'm trying to write a simple macro that will enable the 13 sheet names in a workbook to change based on what the user enters in a cell for what the fiscal year is (our fiscal year is April to March). Currently the 13 sheets are called "April 2017-18, May 2017-18, June 2017-18...March 2018-19", and "Year to Date 2017-18". There is a 14th sheet called "setup" where the user enters data used in some or all of the monthly sheets.

    What I want the user to do is enter the fiscal year in cell A1 of the "setup" sheet (e.g.: user enters "2018-19") as this gets used in the title of all the sheets, but I also want this to trigger name changes to the sheets.

    This will save me from having to update the template's sheet names each year by allowing the users to do it themselves.

    I thank you in advance for the wonderful advice!

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Dynamically change multiple sheet names based upon a cell's value

    Please Login or Register  to view this content.
    Moderator Edit: I added code tags for you. Please remember to use them in the future.
    Last edited by alansidman; 04-30-2018 at 07:04 PM.

  3. #3
    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: Dynamically change multiple sheet names based upon a cell's value

    Here is some code that will do what you ask.
    Please Login or Register  to view this content.
    this code assumes setup looks like the following

    Data Range
    A
    B
    1
    2018-19
    April
    2
    May
    3
    June
    4
    July
    5
    August
    6
    September
    7
    October
    8
    November
    9
    December
    10
    January
    11
    February
    12
    March
    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

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Dynamically change multiple sheet names based upon a cell's value

    Hi Alan.
    Sorry about that.
    Thanks.

  5. #5
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: Dynamically change multiple sheet names based upon a cell's value

    Thank you both very much for the quick responses!

    Both pieces of code work as is. I figured it would be useful to also have a sheet with instructions; hence, I need to also exclude it from being updated with the fiscal year.


    On Alan's code I changed it to
    Please Login or Register  to view this content.
    and it works.


    On jolivane's code I changed it to
    Please Login or Register  to view this content.
    and receive an error message "Invalid procedure call or argument".

    I don't understand why an error on one, but not the other. Could one of you enlighten me? Thanks.

  6. #6
    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: Dynamically change multiple sheet names based upon a cell's value

    double check the sheet names and the code. VBA is case sensitive. Make sure that they are spelled exactly the same. In VBA, "setup" is not equal to "Setup"

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Dynamically change multiple sheet names based upon a cell's value

    I also think it needs to be "And" instead of "Or"

  8. #8
    Registered User
    Join Date
    01-22-2016
    Location
    Canada
    MS-Off Ver
    365
    Posts
    41

    Re: Dynamically change multiple sheet names based upon a cell's value

    I copied/pasted the sheet name into the VBA code, so I know they are exactly the same, but that didn't resolve the error. HOWEVER, when I changed the "Or" to "And", it works like a charm! THANKS!!

+ 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. Dynamically change excel sheet names
    By thong127 in forum Excel General
    Replies: 2
    Last Post: 03-19-2018, 09:25 AM
  2. [SOLVED] Automatically change sheet (tab) names based on cell on sheet1
    By PitBoo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-29-2017, 03:46 PM
  3. Change source of pivot table dynamically based on sheet name
    By jeroenft in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2016, 11:23 AM
  4. Replies: 11
    Last Post: 01-20-2015, 09:34 AM
  5. Automatically Change Sheet Names Based On Cell Values - merged cells
    By Elizabethz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-24-2014, 11:35 AM
  6. change cell names based on new sheet name
    By tdebb8594 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2014, 02:25 PM
  7. Replies: 6
    Last Post: 10-28-2011, 04:39 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