+ Reply to Thread
Results 1 to 10 of 10

Copy a template sheet to end of workbook using a InputBox to rename

  1. #1
    Registered User
    Join Date
    09-11-2016
    Location
    Kalgoorlie, Australia
    MS-Off Ver
    2010
    Posts
    5

    Copy a template sheet to end of workbook using a InputBox to rename

    Hi, my first post and only new to VBA so if I'm in the wrong area or haven't supplied enough info I apologise !!

    I want to have a button set up so users can click it - a inputbox opens up "Enter New Sheet Name" then once you type that in it copies the two template sheets I have set up and pastes them to the end of the workbook with the entered name followed by "_Form" and "Chart"


    This is what I currently have -
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    It creates the one sheet I have in the macro but then gets stuck in a loop...?

    Any help would be really appreciated!!

    Thank you in advance
    Last edited by 6StringJazzer; 09-11-2016 at 08:07 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    First, variable wks is undeclared, and you are ignoring errors. Most likely the line

    Please Login or Register  to view this content.
    is producing an error which your code is ignoring. I recommend you use Option Explicit to guarantee that all variables are declared.

    Also, this is a strange condition to test for:
    Please Login or Register  to view this content.
    Also, you are copying the sheet first, and giving the user no opportunity to cancel the operation. You should get the name from the user first, exiting if he changes his mind.

    I would suggest this rewrite. Note that sName is declared as Variant, because InputBox returns a Variant. It will be a string if the user entered a string, and it will be FALSE if the user pressed Cancel.

    In this solution, if the user does not enter a sheet name, no copy is created. If the user enters a sheet name but the result is invalid, the new sheet is deleted and the user gets an error message.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-11-2016
    Location
    Kalgoorlie, Australia
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    Thank you very much!! That work straight away! Looks like I still have a lot of learning to do! Its all very interesting though.

    My next task is I want to add another sheet to be copied into the macro, I want it to copy a different template sheet (Template_Chart) but rename it the same 'sName' from the InputBox, but "_Chart" after instead.... I'll see if I can add this into your solution.

    Many thanks again, very kind of you!!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    I have not tested this but I think it's straightforward and I expect it to work.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-11-2016
    Location
    Kalgoorlie, Australia
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    Thanks! I did a similar thing but both keep failing at
    Please Login or Register  to view this content.
    I have checked the sheet name is correct and even tried renaming the sheet and in the macro to something different but still fails at the same point.
    Error is 'Run-time error "9":
    Subscript out of range

    Just when I thought I was making sense out of it all.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    That error indicates that there is no worksheet named Chart_Template. I can diagnose it if you attach your file.

    Under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.

  7. #7
    Registered User
    Join Date
    09-11-2016
    Location
    Kalgoorlie, Australia
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    Thank you, again!!

    Sorry - File was to big - have compressed it now - should work this time.
    Attached Files Attached Files
    Last edited by NZ_Shane; 09-11-2016 at 09:56 PM.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    Chart_Template is not a Worksheet, it's a Chart.
    Please Login or Register  to view this content.

    Bedtime in the States now....

  9. #9
    Registered User
    Join Date
    09-11-2016
    Location
    Kalgoorlie, Australia
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    You are an absolute legend!!!

    Thank you very much kind Sir!!!!

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy a template sheet to end of workbook using a InputBox to rename

    You are very welcome and thanks for the rep!

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

+ 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. [SOLVED] Copy Template Sheet and rename the new sheets based on a list in another sheet
    By SaadKiji in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2016, 11:47 AM
  2. [SOLVED] Copy a sheet, rename it by value in range then export product to new workbook and rename
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2015, 07:24 PM
  3. Copy template sheet and rename according to list
    By tkensen89 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2015, 05:13 PM
  4. Replies: 8
    Last Post: 02-26-2013, 01:00 AM
  5. [SOLVED] Copy a sheet (from template) to a new sheet, and rename (based on cell value)
    By Siglen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2012, 10:19 AM
  6. copy template,past new sheet and rename to given date for 30 days
    By fasalazar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 05:19 PM
  7. Copy and rename a sheet in an existing workbook?
    By robertse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-09-2010, 02:00 PM

Tags for this Thread

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