+ Reply to Thread
Results 1 to 4 of 4

Rename Tab Based on Cell Format

Hybrid View

  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Rename Tab Based on Cell Format

    Hello,

    I'm trying to find some code that can rename a tab based on a certain cell's contents.

    I have a random cell (the row is completely random, the column will always be Column A).

    The cell is always an account number- like this: "Account Number 1234567"- the first 16 characters will always be the same, so I'm thinking looking for some VBA code that can recognize the first 16 characters are "Account Number ", and name the sheet the account number "1234567" in this example.

    The account number may vary in length, so the tab should be named whatever characters 17-End are (so I guess it would just remove the first 16 characters?).

    I don't expect anyone to build this code from scratch for me (you know...unless you want to - I'm thinking you guys can post whatever similar code you have and I can modify it to meet this purpose?

    Thanks in advance,

    Chad

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Rename Tab Based on Cell Format

    Hi hope this helps


    Option Explicit
    
    Sub RenameSheet()
    
        Const strKEY_WORD As String = "Account Number"
    
        Dim sh As Worksheet
        Dim rToSearch As Range
        Dim rFound As Range
    
        Set sh = ActiveSheet
        Set rToSearch = sh.Columns("A").Resize(sh.UsedRange.Rows.Count)
    
    
        ' Find the row with the key word.
        Set rFound = rToSearch.Find(What:=strKEY_WORD, LookIn:=xlValues, LookAt:=xlPart, _
                                    SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                    MatchCase:=True, MatchByte:=False, SearchFormat:=False)
    
        ' Check if we found it
        If Not rFound Is Nothing Then
            sh.Name = Replace$(rFound.Value, strKEY_WORD, vbNullString)
        End If
    
    End Sub

  3. #3
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Rename Tab Based on Cell Format

    This worked perfectly, and you're my VBA HERO!

    Thanks so much!

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Rename Tab Based on Cell Format

    I am glad I was able to help.

+ 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. [SOLVED] Rename worksheet tab based on cell value
    By Tritekfire in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-08-2014, 04:22 PM
  3. Rename sheet based on cell value
    By Jason_2112 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 05:09 AM
  4. Rename Tab based on cell value, but only use first 30 characters
    By billuran in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2012, 01:30 PM
  5. insert tab and rename based on cell
    By sput_sput in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2010, 04:12 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