+ Reply to Thread
Results 1 to 19 of 19

Renaming Sheets

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Renaming Sheets

    I have a macro that takes a sheet and splits it into several different sheets, using various loops.

    I am trying to rename the sheets using this code

    Please Login or Register  to view this content.
    It just runs through and doesn't change the name of the sheet.

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Renaming Sheets

    Try this...
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    I tried this on the worksheet both on it's on and by adding it to my code and it does nothing.

    Now the values being used come from cells that I used Text to Columns on. I have no idea if that makes any difference or not. But I have used this code in other macros and it was fine.

  4. #4
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    Here is the full code of the macro, maybe this will help

    Please Login or Register  to view this content.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Renaming Sheets

    It would probably be a good idea to upload the workbook, or a sample, if the data is not sensitive (or can be anonymised)

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    I have uploaded a Dummy worksheet

    DUMMY2.xls

  7. #7
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    I wil have to make some edits to that worksheet

  8. #8
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    This one should work a bit better as I ranamed some cells for it to work.

    DUMMY2.xls

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Renaming Sheets

    Cell C8 does not exist in its own right. It's merged with cell B8 ... so it's not going to have a value and all the conditions fail.


    Regards, TMS

  10. #10
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Renaming Sheets

    Two things I noticed:
    1. If you put my procedure above the Next ws statement, it will cause my procedure to run through every sheet exponentially (ie if you have two sheets it will execute your code twice and my code twice for four executions). Place my code minus the sub end sub parts right below the Next ws statement.

    2. Change cell G2 on your original sheet to one of your test values and unmerge the cell, then run the macro. The original sheet will be renamed O- if you enter Opportunity in G2...

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Renaming Sheets

    Sorry, where is your original code in relation to this workbook?

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Renaming Sheets

    And G2 and H2 are part of a merged cell, A2.

    I'm kind of confused here ...

  13. #13
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    OK... What I did was take A1 and used the Text to Columns to seperate the data in A1 so I can use it. It may have had something like, Issue - I-10 - Problem name and details or Risk - 2 - Risk name and details

    This database wasn't exactly normalized so it gets tricky.

    I seperated A1 by the deliminater -
    Then I did some checks just to get Issue in one cell and the number in the next cell
    I created a G2 and H2 just to check things out but G1 and H1 could be used as well.

    A2 is not merged

  14. #14
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    You need to run the macro that I have created and posted... I made a copy of the orginal sheet and unmerged the cells and got rid of extra columns.

  15. #15
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    DUMMY3.xls


    Sorry, I posted the DUMMY2 worksheet before I left work on Friday.
    I have reposted DUMMY3 and it has the actual code that is to be used. Maybe this will make more sense.
    The Macro unmerges the cells so there are no merged cells being used.

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Renaming Sheets

    I would approach the creation of the Copy sheet and then copying the data to it something like this:

    Please Login or Register  to view this content.

    That would create and name the Copy sheet and, without needing to select the RiskListWithResponses sheet, copy the data to it.


    If all the borders are the same, the adding borders code could be reduced to:

    Please Login or Register  to view this content.

    Regards, TMS

  17. #17
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Renaming Sheets

    Try the amended code below. The problem with the macro is that it was testing for the exact text "Risk", "Opportunity" or "Issue" when the text in each of those tests has a space at the end of it. To remove this problem, I used the Trim function to remove the space. Note that this still leaves some worksheets that don't get renamed since G2 contains text like zzzzzzzz. The amended code looks like this:
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    08-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Renaming Sheets

    Thank you tlafferty, that solved my problem.

  19. #19
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Renaming Sheets

    Glad I could help! Please mark the thread solved (forum rule #9):
    http://www.excelforum.com/forum-rule...rum-rules.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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