+ Reply to Thread
Results 1 to 6 of 6

Copy and rename tabs

  1. #1
    Registered User
    Join Date
    09-18-2009
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    24

    Smile Copy and rename tabs

    Hi,

    I'm trying to create a macro to insert a new tab and rename it to "Consolidation Assumptions".

    However it keeps failing as the sheet thats being inserted may change its existing name, ie - it may be "sheet 9" then next time i run the macro it may be "sheet 10" depending on what i've done before.

    Does any one know the code i should use?

    Any help appreciated,

    Thanks

  2. #2
    Registered User
    Join Date
    09-18-2009
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Copy nad rename tabs

    This is my code...error occurs at "activesheet.select.name" = line

    Sub Consolidation()
    '
    ' Consolidation Macro
    '

    '
    Sheets("Assumptions").Select
    Sheets.Add
    ActiveSheet.Select
    ActiveSheet.Select.Name = "Consolidation Assumptions"
    Range("A1").Select
    End Sub

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Copy nad rename tabs

    Try

    Please Login or Register  to view this content.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Copy nad rename tabs

    or perhaps:

    Please Login or Register  to view this content.
    remember that

    a) you can only have 1 sheet of the same name (case irrelevant) - trying to name a sheet with the same of an existing sheet will throw an error (ie you might want to add a handler)

    b) when a new sheet is added it is immediately the active sheet

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Copy nad rename tabs

    Good point Don,

    I'm going to have to stop rushing, a bit of thought would save me time in the end.

    Cheers

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Copy and rename tabs

    This might be useful if you need to add more than one sheet.

    Please Login or Register  to view this content.

    Try it In a new workbook, it will only add the named sheets once.

    Cheers

+ 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