LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Duplicate worksheet creation

You can use a loop to make it work...
Do
NameBox = Application.InputBox("Please type a name for the _
new worksheet", "Creating New Sheet", , , , , , 2)
if NameBox = "" or NameBox = "False" then
MsgBox "I Told you to type a Name Moron" 'I love abusing the
users...
end if
loop until Not NameBox = "" or NameBox = "False"

HTH

Die_Another_Day
TimN wrote:
My bad....it works now.

Final question (I hope)

If the user closes the message box without entering a name but just presses
OK, an error message occurs: Run-time error '1004'
Method 'Name' of object_Worksheet failed

However a copy is created with a default name of "Sheet(2)". How can I
force an entry in the message box to prevent this error?

Thanks again for your assistance it has been great!

"TimN" wrote:

When I do that, I get a run time error 1004: Copy method of worksheet class
failed

What might be causing that?

"Die_Another_Day" wrote:

yes.
Double-Click your "OK" Button in the editor. This should take you to
the code for this button and should look like this:
Private Sub CommandButton1_Click()

End Sub

Add my code (without the "Sub CopySheet()" and the "End Sub") in
between the Sub End Sub for the commandbutton

HTH

Die_Another_Day
TimN wrote:
Thanks That worked!

I have a user form that asks for some key pieces of information to be
entered. Upon entry the data is placed in various cells and calculations
occur on that data.

Is there a way to make this procedure (the worksheet copy) occur when the
user clicks "OK" on the user form?

"Die_Another_Day" wrote:

Sub CopySheet()
Dim nSheet As Worksheet
Dim NameBox As String
NameBox = Application.InputBox("Please type a name for the new
worksheet", "Creating New Sheet", , , , , , 2)
If NameBox = "False" Then Exit Sub
Sheets("Sheet1").Copy Befo=Sheets(2)
Set nSheet = ActiveSheet
nSheet.Name = NameBox
End Sub
HTH

Die_Another_Day
TimN wrote:
I have read through several posts on this subject, but can't get my situation
to work.
I am trying to write code so that an exact copy of "Sheet1" is made and a
message box appears asking the user to name the new worksheet, for example
the new name might be TimNPayPeriod1.

How can I accomplish this?

Is the code entered in a new module or as part of the user form code?

Thanks for any help!





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show file creation date in a worksheet cell Big Sean Excel Worksheet Functions 3 January 13th 09 07:27 PM
need help with creation of an investment analysis worksheet Brucer New Users to Excel 2 October 15th 07 06:13 PM
pivot table creation in shared worksheet dave in Toronto Excel Discussion (Misc queries) 1 August 9th 07 11:58 PM
Action Item Worksheet Creation Kevin M[_2_] Excel Worksheet Functions 0 February 26th 07 09:16 PM
Automatic new worksheet creation at each change of value in a first worksheet [email protected] Excel Programming 2 July 25th 06 04:23 PM


All times are GMT +1. The time now is 03:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"