Results 1 to 4 of 4

Thread: SImple Excel Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    SImple Excel Problem

    Hi Folks,
    I have a spreadsheet that is hidden from the user (its a blank timesheet master basically). I have another sheet that is not blank called 'instructions', this simply tells the user what to type and where to type.
    The hidden sheet is called say "master".
    All i want to do is put a simple command button on the 'instruction' sheet that will copy the hidden sheet called "master" and present the user with a dialog to get them to type in the new sheet name ie Dec, Jan or Feb etc. Hit return or ok . And then you simply have a new sheet with a name of their choice, whist keeping the master hidden from danger etc.
    Thanx

  2. #2
    New Member
    Join Date
    Dec 2005
    Posts
    4

    Re: SImple Excel Problem

    I found this link that might be of some help.

    http://www.mvps.org/dmcritchie/excel/sheets.htm

    Cheers,
    Carl

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: SImple Excel Problem

    Welcome to the Forums!

    The following should help.

    VB Code:
    1. Sub CopySheet()
    2. Dim MySheet As Worksheet
    3. Dim SheetName As String
    4.  
    5.     'Get The new sheet name from the user
    6.     Do While SheetName = ""
    7.         SheetName = InputBox("Please Enter New Sheet Name", "New Sheet")
    8.     Loop
    9.    
    10.     With ThisWorkbook
    11.         'Copy the master sheet to the end of the workbook
    12.         .Worksheets("Master").Copy After:=.Worksheets(.Worksheets.Count)
    13.         'Rename the last sheet in the workbook
    14.         .Worksheets(.Worksheets.Count).Name = SheetName
    15.         'Make the new sheet visible
    16.         .Worksheets(.Worksheets.Count).Visible = True
    17.     End With
    18. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    Re: SImple Excel Problem

    Thanks Carl and Declan for your replies.
    I tried yours Declan as it was easier form the start.
    It worked a treat but after a few times it came up with a Microsoft Visual Basic window that said:
    Run-Time error '9'
    Subscript out of range
    With the 'end' and 'debug' buttons at the bottom of the dialog window.

    I manually did an unhide on the hidden sheet and found that the name had been left as 'Sheet (2)' presumably as the code had failed half way through and not renamed it back to 'master'.

    I also noticed that if i tried it several times after renaming the sheet back to 'master' and hiding it again the same thing would eventually happen.

    BUT. If i did not hide the sheet named 'master' and left it visible the routine (so far has worked with no problems.

    Any ideas.

    Thanx

Posting Permissions

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



Click Here to Expand Forum to Full Width