+ Reply to Thread
Results 1 to 10 of 10

Rename all existing worksheet tabs

  1. #1
    MikeM
    Guest

    Rename all existing worksheet tabs

    I would like to take an existing workbook and rename all the worksheet tabs
    at one time. For example, I might have ten worksheets with various names and
    I'd like them all to be named USA1, USA2, USA3 and so on.

    Can this be easily done with some VBA code? (I've seen some similar
    questions, but none exactly like this one.)

    Thanks.

  2. #2
    Bob Phillips
    Guest

    Re: Rename all existing worksheet tabs

    Const sBase as string = "USA"
    Dim i as long
    Dim sh As Object

    For Each sh In Activeworkbook.Sheets
    i = i + 1
    sh.name = sBase & i
    Next sh

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > I would like to take an existing workbook and rename all the worksheet

    tabs
    > at one time. For example, I might have ten worksheets with various names

    and
    > I'd like them all to be named USA1, USA2, USA3 and so on.
    >
    > Can this be easily done with some VBA code? (I've seen some similar
    > questions, but none exactly like this one.)
    >
    > Thanks.




  3. #3
    MikeM
    Guest

    Re: Rename all existing worksheet tabs

    Bob:
    Thanks so much for your quick reply! I tried it and it works perfectly.

    Could it be set up so I could define the worksheet name before running the
    macro? (by typing it into a cell or something like that)?

    For example, one workbook might need to be USA1, USA2, etc. and another
    might need to be CANADA1, CANADA2, etc.

    "Bob Phillips" wrote:

    > Const sBase as string = "USA"
    > Dim i as long
    > Dim sh As Object
    >
    > For Each sh In Activeworkbook.Sheets
    > i = i + 1
    > sh.name = sBase & i
    > Next sh
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > I would like to take an existing workbook and rename all the worksheet

    > tabs
    > > at one time. For example, I might have ten worksheets with various names

    > and
    > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > >
    > > Can this be easily done with some VBA code? (I've seen some similar
    > > questions, but none exactly like this one.)
    > >
    > > Thanks.

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Rename all existing worksheet tabs

    Mike,

    This will get it from A1 on Sheet1, change to suit

    Dim sBase as string
    Dim i as long
    Dim sh As Object

    sBase = Worksheets("Sheet1").Range("A1").Value
    For Each sh In Activeworkbook.Sheets
    i = i + 1
    sh.name = sBase & i
    Next sh



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    news:4105ED1A-CAB2-4CA1-A600-FA17E52AFAC3@microsoft.com...
    > Bob:
    > Thanks so much for your quick reply! I tried it and it works perfectly.
    >
    > Could it be set up so I could define the worksheet name before running the
    > macro? (by typing it into a cell or something like that)?
    >
    > For example, one workbook might need to be USA1, USA2, etc. and another
    > might need to be CANADA1, CANADA2, etc.
    >
    > "Bob Phillips" wrote:
    >
    > > Const sBase as string = "USA"
    > > Dim i as long
    > > Dim sh As Object
    > >
    > > For Each sh In Activeworkbook.Sheets
    > > i = i + 1
    > > sh.name = sBase & i
    > > Next sh
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > > I would like to take an existing workbook and rename all the worksheet

    > > tabs
    > > > at one time. For example, I might have ten worksheets with various

    names
    > > and
    > > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > > >
    > > > Can this be easily done with some VBA code? (I've seen some similar
    > > > questions, but none exactly like this one.)
    > > >
    > > > Thanks.

    > >
    > >
    > >




  5. #5
    David McRitchie
    Guest

    Re: Rename all existing worksheet tabs

    Or more likely set up the prefix with an InputBox

    sBase = Application.InputBox("Supply Prefix for worksheet renaming", _
    "Rename worksheets", "USA")
    If sBase = "" Then
    MsgBox "Cancelled by your command"
    exit sub
    end if

    ---
    HTH,
    David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message news:uiv0e82oFHA.2152@TK2MSFTNGP14.phx.gbl...
    > Mike,
    >
    > This will get it from A1 on Sheet1, change to suit
    >
    > Dim sBase as string
    > Dim i as long
    > Dim sh As Object
    >
    > sBase = Worksheets("Sheet1").Range("A1").Value
    > For Each sh In Activeworkbook.Sheets
    > i = i + 1
    > sh.name = sBase & i
    > Next sh
    >
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > news:4105ED1A-CAB2-4CA1-A600-FA17E52AFAC3@microsoft.com...
    > > Bob:
    > > Thanks so much for your quick reply! I tried it and it works perfectly.
    > >
    > > Could it be set up so I could define the worksheet name before running the
    > > macro? (by typing it into a cell or something like that)?
    > >
    > > For example, one workbook might need to be USA1, USA2, etc. and another
    > > might need to be CANADA1, CANADA2, etc.
    > >
    > > "Bob Phillips" wrote:
    > >
    > > > Const sBase as string = "USA"
    > > > Dim i as long
    > > > Dim sh As Object
    > > >
    > > > For Each sh In Activeworkbook.Sheets
    > > > i = i + 1
    > > > sh.name = sBase & i
    > > > Next sh
    > > >
    > > > --
    > > >
    > > > HTH
    > > >
    > > > RP
    > > > (remove nothere from the email address if mailing direct)
    > > >
    > > >
    > > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > > > I would like to take an existing workbook and rename all the worksheet
    > > > tabs
    > > > > at one time. For example, I might have ten worksheets with various

    > names
    > > > and
    > > > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > > > >
    > > > > Can this be easily done with some VBA code? (I've seen some similar
    > > > > questions, but none exactly like this one.)
    > > > >
    > > > > Thanks.
    > > >
    > > >
    > > >

    >
    >




  6. #6
    Bob Phillips
    Guest

    Re: Rename all existing worksheet tabs

    Don't like InputBox Dave, would much rather type in a cell. Too easy to make
    a mistake, maybe not with USA, but easy with Kazakhstan.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "David McRitchie" <dmcritchie_xlmvp@verizon.net> wrote in message
    news:OC48hF3oFHA.1044@tk2msftngp13.phx.gbl...
    > Or more likely set up the prefix with an InputBox
    >
    > sBase = Application.InputBox("Supply Prefix for worksheet renaming",

    _
    > "Rename worksheets", "USA")
    > If sBase = "" Then
    > MsgBox "Cancelled by your command"
    > exit sub
    > end if
    >
    > ---
    > HTH,
    > David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    > My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    > Search Page: http://www.mvps.org/dmcritchie/excel/search.htm
    >
    > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message

    news:uiv0e82oFHA.2152@TK2MSFTNGP14.phx.gbl...
    > > Mike,
    > >
    > > This will get it from A1 on Sheet1, change to suit
    > >
    > > Dim sBase as string
    > > Dim i as long
    > > Dim sh As Object
    > >
    > > sBase = Worksheets("Sheet1").Range("A1").Value
    > > For Each sh In Activeworkbook.Sheets
    > > i = i + 1
    > > sh.name = sBase & i
    > > Next sh
    > >
    > >
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > news:4105ED1A-CAB2-4CA1-A600-FA17E52AFAC3@microsoft.com...
    > > > Bob:
    > > > Thanks so much for your quick reply! I tried it and it works

    perfectly.
    > > >
    > > > Could it be set up so I could define the worksheet name before running

    the
    > > > macro? (by typing it into a cell or something like that)?
    > > >
    > > > For example, one workbook might need to be USA1, USA2, etc. and

    another
    > > > might need to be CANADA1, CANADA2, etc.
    > > >
    > > > "Bob Phillips" wrote:
    > > >
    > > > > Const sBase as string = "USA"
    > > > > Dim i as long
    > > > > Dim sh As Object
    > > > >
    > > > > For Each sh In Activeworkbook.Sheets
    > > > > i = i + 1
    > > > > sh.name = sBase & i
    > > > > Next sh
    > > > >
    > > > > --
    > > > >
    > > > > HTH
    > > > >
    > > > > RP
    > > > > (remove nothere from the email address if mailing direct)
    > > > >
    > > > >
    > > > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > > > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > > > > I would like to take an existing workbook and rename all the

    worksheet
    > > > > tabs
    > > > > > at one time. For example, I might have ten worksheets with

    various
    > > names
    > > > > and
    > > > > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > > > > >
    > > > > > Can this be easily done with some VBA code? (I've seen some

    similar
    > > > > > questions, but none exactly like this one.)
    > > > > >
    > > > > > Thanks.
    > > > >
    > > > >
    > > > >

    > >
    > >

    >
    >




  7. #7
    MikeM
    Guest

    Re: Rename all existing worksheet tabs

    Many thanks to you Bob, and David as well for such quick and informative
    responses. This is the first time I've posted a question here and will
    certainly continue to do so in the future!
    Mike

    "Bob Phillips" wrote:

    > Don't like InputBox Dave, would much rather type in a cell. Too easy to make
    > a mistake, maybe not with USA, but easy with Kazakhstan.
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "David McRitchie" <dmcritchie_xlmvp@verizon.net> wrote in message
    > news:OC48hF3oFHA.1044@tk2msftngp13.phx.gbl...
    > > Or more likely set up the prefix with an InputBox
    > >
    > > sBase = Application.InputBox("Supply Prefix for worksheet renaming",

    > _
    > > "Rename worksheets", "USA")
    > > If sBase = "" Then
    > > MsgBox "Cancelled by your command"
    > > exit sub
    > > end if
    > >
    > > ---
    > > HTH,
    > > David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    > > My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    > > Search Page: http://www.mvps.org/dmcritchie/excel/search.htm
    > >
    > > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message

    > news:uiv0e82oFHA.2152@TK2MSFTNGP14.phx.gbl...
    > > > Mike,
    > > >
    > > > This will get it from A1 on Sheet1, change to suit
    > > >
    > > > Dim sBase as string
    > > > Dim i as long
    > > > Dim sh As Object
    > > >
    > > > sBase = Worksheets("Sheet1").Range("A1").Value
    > > > For Each sh In Activeworkbook.Sheets
    > > > i = i + 1
    > > > sh.name = sBase & i
    > > > Next sh
    > > >
    > > >
    > > >
    > > > --
    > > >
    > > > HTH
    > > >
    > > > RP
    > > > (remove nothere from the email address if mailing direct)
    > > >
    > > >
    > > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > > news:4105ED1A-CAB2-4CA1-A600-FA17E52AFAC3@microsoft.com...
    > > > > Bob:
    > > > > Thanks so much for your quick reply! I tried it and it works

    > perfectly.
    > > > >
    > > > > Could it be set up so I could define the worksheet name before running

    > the
    > > > > macro? (by typing it into a cell or something like that)?
    > > > >
    > > > > For example, one workbook might need to be USA1, USA2, etc. and

    > another
    > > > > might need to be CANADA1, CANADA2, etc.
    > > > >
    > > > > "Bob Phillips" wrote:
    > > > >
    > > > > > Const sBase as string = "USA"
    > > > > > Dim i as long
    > > > > > Dim sh As Object
    > > > > >
    > > > > > For Each sh In Activeworkbook.Sheets
    > > > > > i = i + 1
    > > > > > sh.name = sBase & i
    > > > > > Next sh
    > > > > >
    > > > > > --
    > > > > >
    > > > > > HTH
    > > > > >
    > > > > > RP
    > > > > > (remove nothere from the email address if mailing direct)
    > > > > >
    > > > > >
    > > > > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > > > > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > > > > > I would like to take an existing workbook and rename all the

    > worksheet
    > > > > > tabs
    > > > > > > at one time. For example, I might have ten worksheets with

    > various
    > > > names
    > > > > > and
    > > > > > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > > > > > >
    > > > > > > Can this be easily done with some VBA code? (I've seen some

    > similar
    > > > > > > questions, but none exactly like this one.)
    > > > > > >
    > > > > > > Thanks.
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    >


  8. #8
    MikeM
    Guest

    Re: Rename all existing worksheet tabs

    David:
    I tried this solution and it works nicely as well. Many thanks!
    Mike

    "David McRitchie" wrote:

    > Or more likely set up the prefix with an InputBox
    >
    > sBase = Application.InputBox("Supply Prefix for worksheet renaming", _
    > "Rename worksheets", "USA")
    > If sBase = "" Then
    > MsgBox "Cancelled by your command"
    > exit sub
    > end if
    >
    > ---
    > HTH,
    > David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    > My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    > Search Page: http://www.mvps.org/dmcritchie/excel/search.htm
    >
    > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message news:uiv0e82oFHA.2152@TK2MSFTNGP14.phx.gbl...
    > > Mike,
    > >
    > > This will get it from A1 on Sheet1, change to suit
    > >
    > > Dim sBase as string
    > > Dim i as long
    > > Dim sh As Object
    > >
    > > sBase = Worksheets("Sheet1").Range("A1").Value
    > > For Each sh In Activeworkbook.Sheets
    > > i = i + 1
    > > sh.name = sBase & i
    > > Next sh
    > >
    > >
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > news:4105ED1A-CAB2-4CA1-A600-FA17E52AFAC3@microsoft.com...
    > > > Bob:
    > > > Thanks so much for your quick reply! I tried it and it works perfectly.
    > > >
    > > > Could it be set up so I could define the worksheet name before running the
    > > > macro? (by typing it into a cell or something like that)?
    > > >
    > > > For example, one workbook might need to be USA1, USA2, etc. and another
    > > > might need to be CANADA1, CANADA2, etc.
    > > >
    > > > "Bob Phillips" wrote:
    > > >
    > > > > Const sBase as string = "USA"
    > > > > Dim i as long
    > > > > Dim sh As Object
    > > > >
    > > > > For Each sh In Activeworkbook.Sheets
    > > > > i = i + 1
    > > > > sh.name = sBase & i
    > > > > Next sh
    > > > >
    > > > > --
    > > > >
    > > > > HTH
    > > > >
    > > > > RP
    > > > > (remove nothere from the email address if mailing direct)
    > > > >
    > > > >
    > > > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > > > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > > > > I would like to take an existing workbook and rename all the worksheet
    > > > > tabs
    > > > > > at one time. For example, I might have ten worksheets with various

    > > names
    > > > > and
    > > > > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > > > > >
    > > > > > Can this be easily done with some VBA code? (I've seen some similar
    > > > > > questions, but none exactly like this one.)
    > > > > >
    > > > > > Thanks.
    > > > >
    > > > >
    > > > >

    > >
    > >

    >
    >
    >


  9. #9
    dford
    Guest

    Re: Rename all existing worksheet tabs

    I would like to rename just selected worksheets. Could a modification of this
    code be possible?

    "Bob Phillips" wrote:

    > Const sBase as string = "USA"
    > Dim i as long
    > Dim sh As Object
    >
    > For Each sh In Activeworkbook.Sheets
    > i = i + 1
    > sh.name = sBase & i
    > Next sh
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > I would like to take an existing workbook and rename all the worksheet

    > tabs
    > > at one time. For example, I might have ten worksheets with various names

    > and
    > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > >
    > > Can this be easily done with some VBA code? (I've seen some similar
    > > questions, but none exactly like this one.)
    > >
    > > Thanks.

    >
    >
    >


  10. #10
    Bob Phillips
    Guest

    Re: Rename all existing worksheet tabs

    Const sBase As String = "USA"
    Dim i As Long
    Dim sh As Object

    For Each sh In ActiveWorkbook.Windows(1).SelectedSheets
    i = i + 1
    sh.Name = sBase & i
    Next sh

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with googlemail if mailing direct)

    "dford" <dford@discussions.microsoft.com> wrote in message
    news:741C6203-2665-4EEB-9011-20F06678D1D9@microsoft.com...
    > I would like to rename just selected worksheets. Could a modification of

    this
    > code be possible?
    >
    > "Bob Phillips" wrote:
    >
    > > Const sBase as string = "USA"
    > > Dim i as long
    > > Dim sh As Object
    > >
    > > For Each sh In Activeworkbook.Sheets
    > > i = i + 1
    > > sh.name = sBase & i
    > > Next sh
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "MikeM" <michael[dot]mittelmanl[at]db[dot]com> wrote in message
    > > news:ECE18B9C-D5AB-4D2C-9807-137E2CF24FD7@microsoft.com...
    > > > I would like to take an existing workbook and rename all the worksheet

    > > tabs
    > > > at one time. For example, I might have ten worksheets with various

    names
    > > and
    > > > I'd like them all to be named USA1, USA2, USA3 and so on.
    > > >
    > > > Can this be easily done with some VBA code? (I've seen some similar
    > > > questions, but none exactly like this one.)
    > > >
    > > > Thanks.

    > >
    > >
    > >




+ 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