+ Reply to Thread
Results 1 to 11 of 11

Rename active sheet based on cell value.

Hybrid View

Dagoom Rename active sheet based on... 11-09-2013, 08:35 PM
alansidman Re: Rename active sheet based... 11-09-2013, 09:40 PM
Dagoom Re: Rename active sheet based... 11-09-2013, 10:06 PM
alansidman Re: Rename active sheet based... 11-10-2013, 12:08 AM
Dagoom Re: Rename active sheet based... 11-10-2013, 01:17 AM
protonLeah Re: Rename active sheet based... 11-10-2013, 01:49 AM
Dagoom Re: Rename active sheet based... 11-10-2013, 02:04 AM
protonLeah Re: Rename active sheet based... 11-10-2013, 02:16 AM
Dagoom Re: Rename active sheet based... 11-10-2013, 02:46 AM
Dagoom Re: Rename active sheet based... 11-10-2013, 02:49 AM
protonLeah Re: Rename active sheet based... 11-10-2013, 06:12 PM
  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    45

    Rename active sheet based on cell value.

    Hello all,

    I was wondering if anyone can help me out here.

    I have a few macros set up to copy a sheet, and add a row to my table.

    Now what I need to know, can I rename my active sheet based on the bottom value in a range?

    I have associated my table as "Table1" and what Would be great is if I could rename a sheet the bottom value in Column A.

    Please help me out here, I am so close to finally finishing this project.

    Thanks for your time.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,761

    Re: Rename active sheet based on cell value.

    Have a look at this link:

    http://www.ozgrid.com/forum/showthread.php?t=65841
    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

  3. #3
    Registered User
    Join Date
    04-16-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Rename active sheet based on cell value.

    Thanks Alan, is there any way to have it select the last cell with data in it in a range?

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,761

    Re: Rename active sheet based on cell value.

    Yes. Try this:

    Option Explicit 
     
    Sub add_Sheet_name() 
        Dim sShtName As String
        Dim lr As Long
        lr = Range("A" & Rows.Count).End(xlUp).Row
    
         
        sShtName =   Range("A" & lr).Value
         
        If Not WksExists(sShtName) Then Worksheets.Add After:=Worksheets(Worksheets.Count) 
         
        ActiveSheet.Name = sShtName 
    End Sub 
    Function WksExists(wksName As String) As Boolean 
        On Error Resume Next 
        WksExists = CBool(Len(Worksheets(wksName).Name) > 0) 
    End Function

  5. #5
    Registered User
    Join Date
    04-16-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Rename active sheet based on cell value.

    Unfortunately what it does is make a new sheet, not just rename the active one.

    Is there any way to add renaming the sheet to this macro?

    All of my sheet names are numbered 1-100, this macro creates a page from a template, adds a row to my table and now all I need to do is make it rename the page after the new row, which in this case would have "101" as a name.

    Sub AddRow_CopySheet_Rename()
        Application.ScreenUpdating = False
        Dim Sheet2 As Variant
        Set Sheet2 = Worksheets("Template")
        Sheet2.Visible = True
        Dim CellX As Range
        Set CellX = ActiveCell
        ActiveWorkbook.Sheets(1).Activate
        Range("Table2").Select
        Selection.ListObject.ListRows.Add AlwaysInsert:=True
        Range("InsertSection").Select
        Dim WS As Worksheet, WB As Workbook
        Set WB = ActiveWorkbook
        Set WS = WB.Sheets("Template")
        WS.Copy After:=Sheets(WB.Sheets.Count)
        Application.Goto CellX
        Sheet2.Visible = False
        Application.ScreenUpdating = True
    End Sub
    Thanks for your help Alan. I really appreciate it.

    Right now my new sheet is called "Template (2)".

    I would like it to be named 101 in this case.

    Then the next sheet when I run the macro would be 102.
    Last edited by Dagoom; 11-10-2013 at 01:21 AM.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Rename active sheet based on cell value.

    Are you adding a new sheet and then renaming it, or just renaming an existing sheet?
    Ben Van Johnson

  7. #7
    Registered User
    Join Date
    04-16-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Rename active sheet based on cell value.

    I am adding a sheet with my one macro, then was planning on adding the second macro to the first to rename it using the last used cell in my table, or range of A column.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Rename active sheet based on cell value.

    Try this mods using alansidman's code above:

    Option Explicit
    Sub AddRow_CopySheet_Rename()
        Application.ScreenUpdating = False
        Dim Sheet2 As Variant
        Dim CellX As Range
        Dim WS As Worksheet, WB As Workbook
    '-----------------------------
        Dim sShtName As String
        Dim lr As Long
    '------------------------------
        Set Sheet2 = Worksheets("Template")
        Sheet2.Visible = True
        Set CellX = ActiveCell
        ActiveWorkbook.Sheets(1).Activate
        Range("Table2").Select
        Selection.ListObject.ListRows.Add AlwaysInsert:=True
    '-------------------------------
        lr = Range("A" & Rows.Count).End(xlUp).Row
        sShtName = Range("A" & lr).Value
    '-------------------------------
        Range("InsertSection").Select
        Set WB = ActiveWorkbook
        Set WS = WB.Sheets("Template")
        WS.Copy After:=Sheets(WB.Sheets.Count)
    '-------------------------------
        ActiveSheet.Name = sShtName
    '-------------------------------
        Application.Goto CellX
        Sheet2.Visible = False
        Application.ScreenUpdating = True
    End Sub
    Last edited by protonLeah; 11-10-2013 at 05:55 PM.

  9. #9
    Registered User
    Join Date
    04-16-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Rename active sheet based on cell value.

    THANK YOU SO MUCH!

    That works amazingly.

    You are the man.

  10. #10
    Registered User
    Join Date
    04-16-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Rename active sheet based on cell value.

    Is there any way to make it so if the number in Column A is below 99, it adds a different template?

    If not it's not a huge deal, you guys have done more than enough for me.

    Oops, sorry for the double post.
    Last edited by Dagoom; 11-10-2013 at 02:57 AM. Reason: Didn't mean to double post.

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Rename active sheet based on cell value.

    Something like:

    Option Explicit
    Sub AddRow_CopySheet_Rename()
        Application.ScreenUpdating = False
        Dim Sheet2 As Variant
        Dim CellX As Range
        Dim WS As Worksheet, WB As Workbook
    '-----------------------------
        
        Dim sShtName As String
        Dim lr As Long
        
    '------------------------------
        Set Sheet2 = Worksheets("Template")
        Sheet2.Visible = True
        Set CellX = ActiveCell
        ActiveWorkbook.Sheets(1).Activate
        Range("Table2").Select
        Selection.ListObject.ListRows.Add AlwaysInsert:=True
    '-------------------------------
        
        lr = Range("A" & Rows.Count).End(xlUp).Row
        sShtName = Range("A" & lr).Value
        
    '-------------------------------
        Range("InsertSection").Select
        Set WB = ActiveWorkbook
    
        Select Case lr
            Case Is < 99
                Set WS = WB.Sheets("template2")
            Case Is >= 99
                Set WS = WB.Sheets("Template")
        End Select
    
        WS.Copy After:=Sheets(WB.Sheets.Count)
    '-------------------------------
        
        ActiveSheet.Name = sShtName
        
    '-------------------------------
        Application.Goto CellX
        Sheet2.Visible = False
        Application.ScreenUpdating = True
    End Sub

+ 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. Rename Sheet based on Cell Value
    By Vetequk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2015, 09:07 PM
  2. Create A Copy To A New Sheet & Rename Sheet Based on Cell Value
    By delicard in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 07-25-2013, 08:56 PM
  3. [SOLVED] Copy a sheet (from template) to a new sheet, and rename (based on cell value)
    By Siglen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2012, 10:19 AM
  4. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  5. [SOLVED] Rename active sheet to contents of specific cell
    By burl_rfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2006, 07:40 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