Results 1 to 3 of 3

Thread: VBA copy worksheet with option to rename
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Oct 2010
    Location
    Halesowen, West Midlands
    Posts
    367
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA copy worksheet with option to rename

    Hi.

    I'd like to have a button on Sheet 1 where the user clicks it and it creates an exact copy of Sheet 1* but up pops a little box that says "Please enter your name below then click Ok" and when they do that, it creates a new worksheet that is an exact replica of what's on Sheet 1 (even down to the button that the user clicked in the first place).

    It doesn't really matter where within the other worksheets this newly created one is put in - what's important is that the worksheet is exactly the same as the one on Sheet 1 and they name it by their name.

    The only potential problems I see with this is 1. names that are really long, too long to sit on a worksheet tab title and 2. people with the same names - any ideas within the context/restrictions of an Excel worksheet that would change how I've described wanting this would also be very useful as for the users, I think having a worksheet with their name will give them ownership of their worksheet and be really easy for them to go in and add their data in so I'd like to try and stick with using names.

    * = Sheet 1 is going to be named Create My Data Entry Template btw.

    Can you kindly also advise when I'm adding in the VBA, do I put it in a 'General', 'Declarations' window??

    I will need help with how to go about creating the macro button as well to make sure that I get that bit right.

    Thank you.

  2. #2
    Board Regular
    Join Date
    Oct 2010
    Location
    Halesowen, West Midlands
    Posts
    367
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA copy worksheet with option to rename

    Apologies, missed the editing window.

    Is there a formula or something that could be added to the above VBA, that when they pick the name and the new worksheet is created with that name, it also inserts the worksheet name (ie their name) in cell A1???

  3. #3
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,254
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: VBA copy worksheet with option to rename

    How about
    Code:
    Sub halesowenmum()
        Dim ShtName As String
        Dim Flg As Boolean
        
        Do Until Flg
            ShtName = InputBox("Please enter your name")
            If ShtName = "" Then Exit Sub
            If Len(ShtName) > 31 Then
                MsgBox ("The name is too long")
            ElseIf Evaluate("isref('" & ShtName & "'!A1)") Then
                MsgBox ("That name is taken")
            Else
                Flg = True
            End If
        Loop
        Sheets("Lists").Copy , ActiveSheet
        With ActiveSheet
            .Name = ShtName
            .Range("A1").Value = ShtName
        End With
    End Sub
    To create the button goto the Developer tab > Insert > Select button icon (top left) under Form Controls > Click on the sheet where you want the button, when the Assign Macro window pops up select the macro name & click ok.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •