+ Reply to Thread
Results 1 to 16 of 16

Rename Sheets in a Workbook

  1. #1
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Rename Sheets in a Workbook

    Hi Everyone,
    the following code gives all worksheets in a workbook the name of the string found in cell A1.

    But I have the problem that I have sheets which have only one word. Then the script does not work anymore.

    Also I would like to have the complete content of cell A1 as sheet name no matter what is in it.

    Maybe you can help me to adjust the code to use all characters in cell A1 as sheet names of the respective sheet.

    Here is the Code:
    Please Login or Register  to view this content.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Rename Sheets in a Workbook

    the reason it doesn't work is because you spec'd the delimiter as a space using split(). that function only does one thing.
    you can't make it do anymore. the best workaround, IMO, is to create sheets that do you not have spaces in them. that is, after all,
    protocol for all developers anyway. spaces create very bad issues. that's why SEO addresses on websites do not have spaces in them.
    they have dashes (-) or underscores (_).
    Attached Images Attached Images

  3. #3
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Rename Sheets in a Workbook

    What's wrong with just using this line?
    Please Login or Register  to view this content.
    So this would be your entire code..
    Please Login or Register  to view this content.
    Last edited by Croweater; 11-29-2020 at 06:43 PM.

  4. #4
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Re: Rename Sheets in a Workbook

    Thank you for your help:
    It gives me an error in this line:

    Please Login or Register  to view this content.

    And there is a Problem with sheetnames with only one word.
    Is there a chance that you can add underscores (_) in the sheetname.
    I would not mind that.
    But I am just a layman.

    As an alternative solution 2 words should also be enough. But I also have texts in A1, which contain only one word.
    And then the vb a doesn't work no more.

    Thank you for your help.
    Last edited by CoSinus; 11-30-2020 at 08:01 AM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,597

    Re: Rename Sheets in a Workbook

    Some possible error for renaming sheet.

    1) Can't use the name that already exists in the workbook.
    2) Length must be less than 31 characters.
    3) Use of invalid characters i.e. : ? \ [ ] / *

    If you don't care about above then simply
    Please Login or Register  to view this content.

  6. #6
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Rename Sheets in a Workbook

    Quote Originally Posted by CoSinus View Post
    Thank you for your help:
    It gives me an error in this line:

    Please Login or Register  to view this content.
    What is the error? Can you post a workbook to demonstrate that error?


    And there is a Problem with sheetnames with only one word.
    Did you take out the line where you are trying to SPLIT the cell using the space (as I posted above)?
    If you copy the code I pasted this should not be a problem.

  7. #7
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Re: Rename Sheets in a Workbook

    @jindon:

    Here is an error in
    Please Login or Register  to view this content.
    I send you the excel file.

    As you can see in the sample Sheet the Sheetnames do not carry the strings in A1.

    Thanks all for your help so much.
    Attached Files Attached Files
    Last edited by CoSinus; 11-30-2020 at 10:59 AM.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Rename Sheets in a Workbook

    Some of the A1 cells have char > 31...
    Time Spent on Decisions by Teams = 32 Char

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,597

    Re: Rename Sheets in a Workbook

    As I mentioned already, length...
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Re: Rename Sheets in a Workbook

    Thank you all for your help.
    The solution in the end is perfect.

    I am very grateful.

  11. #11
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Re: Rename Sheets in a Workbook

    I know that the thread was closed,
    but I have worked on a code with your help that could deal with the problem of the string length.
    The Code has flaws. Could you please help me.

    To test it I attached a document that has too long names in A! on some sheets which are partly the same.

    The goal of the code should be to cut off the characters and to add a numbering in case of duplicate designations, so that no error message appears.

    I am glad about your help to correct the code.

    Thanks a lot

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by CoSinus; 12-01-2020 at 08:06 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,597

    Re: Rename Sheets in a Workbook

    This is atypical human error when you did not enable Option Explicit to force the variables to be declared.
    If you add Option Explicit at the top of the module, it will tell you the variable(s) that are not declared.

  13. #13
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Re: Rename Sheets in a Workbook

    Thanks for the Tip.
    I did it and made changes.
    I guess it is almost working.

    Here is the revised vba:

    Please Login or Register  to view this content.
    Small error with
    Please Login or Register  to view this content.
    Maybe someone can check please.
    Thanks everybody!
    Last edited by CoSinus; 12-01-2020 at 01:05 PM.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Rename Sheets in a Workbook

    Play around with this...
    Please Login or Register  to view this content.

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,597

    Re: Rename Sheets in a Workbook

    CoSinus

    Refer to my Post#5 for Error renaming sheet.
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    05-24-2020
    Location
    London
    MS-Off Ver
    Office 365 pro
    Posts
    177

    Re: Rename Sheets in a Workbook

    Thank you very much.
    I have been looking for a solution to this problem for so long.

    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. [SOLVED] macro to rename all sheets in workbook as criteria cells A2 of each sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2019, 04:44 PM
  2. [SOLVED] Loop worksheets and if sheets Name matches pattern, rename sheets
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2016, 01:08 AM
  3. [SOLVED] Copy a sheet, rename it by value in range then export product to new workbook and rename
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2015, 07:24 PM
  4. Replies: 0
    Last Post: 02-06-2015, 04:50 PM
  5. copy sheets to new workbook with new name, rename tabs within that workbook
    By Conky4 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2012, 04:44 PM
  6. [SOLVED] Code to create new sheet and rename, regardless of any other sheets in workbook
    By csh8428 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2012, 02:22 PM
  7. Code to delete sheets and rename sheets in a protected workbook?
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-07-2011, 03:02 AM

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