+ Reply to Thread
Results 1 to 11 of 11

Macro needed to name excel tabs based on unique cells within each tab

Hybrid View

  1. #1
    Registered User
    Join Date
    08-13-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    88

    Macro needed to name excel tabs based on unique cells within each tab

    Hi Everyone,

    I need a macro that will name the tab based on a particular cell but I need this to be automated so it does it for all tabs also.

    Database sheet.xlsx

    Any help would be greatly appreciated!

    An explanation of what I need done can be seen below!

    Cheers

    -----

    1) All experiment tabs to be c2 for their respective cells
    2) In the tab combined sheet the "Expt1" must be labelled to the corresponding new name for the tab.

    E.G

    EXPT 1 gets changed to - Forest Park

    I want it to be in my list as Forest Park in the combined sheet.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro needed to name excel tabs based on unique cells within each tab

    Hi Ardiko

    Try this Code...place the Code in ThisWorkbook Module
    Option Explicit
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
        Dim ws As Worksheet, ws1 As Worksheet
        Dim sName As Range
        Dim OldValue As String
    
        Set ws = ActiveSheet
        Set ws1 = Sheets("COMBINED SHEET")
        If Not ws.Name = "Combined Sheet" Then
            If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
            If Target.Address = "$C$2" Then
                OldValue = ActiveSheet.Name
                ActiveSheet.Name = Target.Cells.Value
                With ws1.Columns(1)
                    Set sName = .Find(OldValue, LookIn:=xlValues)
                    sName = ActiveSheet.Name
                End With
            End If
        End If
    
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    08-13-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: Macro needed to name excel tabs based on unique cells within each tab

    Thanks Jas for the solution but how do I copy it into the workbook? I normally start my Macros with Sub etc so I'm a bit lost.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro needed to name excel tabs based on unique cells within each tab

    Hi Ardiko

    To insert the Code into your Workbook:
    1. Go into VBA ----> Alt + F11
    2. Click on ThisWorkbook in the Left Hand Panel
    3. Paste the Code in the Right Hand Panel
    4. Exit Vba
    5. Save the File as a Macro Enabled File (.xlsm)
    I've attached your Sample File with the Code embedded.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-13-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: Macro needed to name excel tabs based on unique cells within each tab

    Thanks Jas! That's awesome! :D

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro needed to name excel tabs based on unique cells within each tab

    You're welcome...glad I could help. Thanks for the Rep.

    If this resolves your issue please mark your Thread as SOLVED.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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. Macro Needed to delete range of cells based on null values in another cell
    By jeffmarsiglio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 08:22 AM
  2. [SOLVED] Macro - Copy and Combine values in cell and paste it in other cells based on Unique ID
    By haleakala17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2012, 05:41 PM
  3. [SOLVED] Excel Macro for Cutting Rows based upon Column B into new Tabs in the same workbook
    By paulzzed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2012, 02:49 AM
  4. [SOLVED] Filtering and generating new tabs based on Unique values based in column
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-02-2012, 09:40 PM
  5. Replies: 6
    Last Post: 02-01-2012, 05:29 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