+ Reply to Thread
Results 1 to 10 of 10

VBA / MACRO - naming a worksheet based on a cell value

  1. #1
    Registered User
    Join Date
    11-30-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    10

    VBA / MACRO - naming a worksheet based on a cell value

    Hi all. I am using the following vba code to name a worksheet based on a cell (B1) value:

    Please Login or Register  to view this content.
    The issue I run into is, when B1 is a percentage such as 50%, the worksheet name becomes "0.5 Scenario" instead of "50% Scenario". Is there a way to show "50% Scenario"? Thank you very much.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,443

    Re: VBA / MACRO - naming a worksheet based on a cell value

    Hi,

    Try this:

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,691

    Re: VBA / MACRO - naming a worksheet based on a cell value

    This will use whatever is in B1 just as displayed, whether it's % or any other format:

    Please Login or Register  to view this content.


    Bad advice, doesn't work, don't do this.
    Last edited by 6StringJazzer; 12-02-2020 at 09:18 AM.

  4. #4
    Registered User
    Join Date
    11-30-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    10

    Re: VBA / MACRO - naming a worksheet based on a cell value

    Thank you very much sweept it works. A follow up question. Now the worksheet name changed, one hyperlink to the worksheet fails (reference isn't valid). The hyperlink is contained in a button in the first worksheet (table of contents) of the workbook. Is there a way to update the hyperlink automatically?

  5. #5
    Registered User
    Join Date
    11-30-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    10

    Re: VBA / MACRO - naming a worksheet based on a cell value

    Quote Originally Posted by 6StringJazzer View Post
    This will use whatever is in B1 just as displayed, whether it's % or any other format:

    Please Login or Register  to view this content.
    Hi thank you for the reply. Are you saying the code should be the following?:

    Please Login or Register  to view this content.
    This does not work for me though. Got a run time error "438".

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,691

    Re: VBA / MACRO - naming a worksheet based on a cell value

    Quote Originally Posted by ttch View Post
    This does not work for me though. Got a run time error "438".
    My mistake, go with sweep's solution.

  7. #7
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,443

    Re: VBA / MACRO - naming a worksheet based on a cell value

    The hyperlink is contained in a button in the first worksheet (table of contents) of the workbook. Is there a way to update the hyperlink automatically?
    Almost certainly. What sort of button - a form control, active X, or a shape with a hyperlink?

  8. #8
    Registered User
    Join Date
    11-30-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    10

    Re: VBA / MACRO - naming a worksheet based on a cell value

    Hi sweep it's just a shape with a hyperlink.

  9. #9
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,443

    Re: VBA / MACRO - naming a worksheet based on a cell value

    OK,

    So you can change the hyperlink subaddress to match the sheet name. Something along these lines should work.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-30-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    10

    Re: VBA / MACRO - naming a worksheet based on a cell value

    Quote Originally Posted by sweep View Post
    OK,

    So you can change the hyperlink subaddress to match the sheet name. Something along these lines should work.

    Please Login or Register  to view this content.
    Thank you very much sweep. Much appreciated.

+ 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] Naming worksheet automatically from cell data
    By arjoyce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-25-2013, 05:49 AM
  2. Macro to select worksheet based on cell value and then return data to diff worksheet
    By clnossok in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2013, 07:48 PM
  3. Naming sheets based on List in same worksheet
    By Jacob_J in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-23-2012, 05:55 AM
  4. Naming Worksheet after cell values
    By kaffal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2009, 08:38 AM
  5. Naming a worksheet from a cell in another worksheet
    By sportsranker in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-20-2008, 11:02 AM
  6. naming a worksheet using a cell value
    By fry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2007, 05:15 AM
  7. Naming a worksheet based on cell data
    By compta_8 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-16-2005, 03:51 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