Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy sheet and prompt for sheet name


I want to be able to create a copy of an existing sheet and have the
user specify the sheet name as it copies, rather than wait until they
have copied it and then change the name manually. Ideally, after
clicking the command button to copy the name, the user will be prompted
to type in the sheet name.

The code I have for creating the copy is as follows (taken straight
from a macro), and it's the .Name = "domain.com" section I need to be
able to specify.

Private Sub CommandButton1_Click()
Sheets("Template.com").Select
Sheets("Template.com").Copy After:=Sheets(2)
Sheets("Template.com (2)").Select
Sheets("Template.com (2)").Name = "domain.com"
End Sub

Any advice greatly appreciated, thanks.

Mxx


--
murphyz
------------------------------------------------------------------------
murphyz's Profile: http://www.excelforum.com/member.php...o&userid=20624
View this thread: http://www.excelforum.com/showthread...hreadid=484219

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy sheet and prompt for sheet name

Check the InputBox function. Start your sub by collecting in a string
variable the name of the worksheet and Exit from it if Inputbox returned an
empty string; ELSE proceed with the rest of your sub.
--
Stefano Gatto


"murphyz" wrote:


I want to be able to create a copy of an existing sheet and have the
user specify the sheet name as it copies, rather than wait until they
have copied it and then change the name manually. Ideally, after
clicking the command button to copy the name, the user will be prompted
to type in the sheet name.

The code I have for creating the copy is as follows (taken straight
from a macro), and it's the .Name = "domain.com" section I need to be
able to specify.

Private Sub CommandButton1_Click()
Sheets("Template.com").Select
Sheets("Template.com").Copy After:=Sheets(2)
Sheets("Template.com (2)").Select
Sheets("Template.com (2)").Name = "domain.com"
End Sub

Any advice greatly appreciated, thanks.

Mxx


--
murphyz
------------------------------------------------------------------------
murphyz's Profile: http://www.excelforum.com/member.php...o&userid=20624
View this thread: http://www.excelforum.com/showthread...hreadid=484219


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy sheet and prompt for sheet name


Thank you, I'm getting there slowly.

I now have it almost working perfectly, although when pressing cancel
it ignores my 'you clicked cancel' text and prints out the 'you didn't
enter anything' text - am I missing something silly?

mystring = InputBox("Please enter sheet name here")
If mystring = False Then
MsgBox "You clicked cancel"
ElseIf mystring = "" Then
MsgBox "You didn't enter anything"
Else
Sheets("Template.com").Visible = True
Sheets("Template.com").Select
Sheets("Template.com").Copy After:=Sheets(2)
Sheets("Template.com (2)").Select
Sheets("Template.com (2)").Name = mystring
Sheets("Template.com").Select
ActiveWindow.SelectedSheets.Visible = False
End If

Finally, is there a way to copy the sheet to the very end of the tabs -
Copy After:=Sheets(2) - regardless of how many worksheets there are?

Many thanks

Mxx


--
murphyz
------------------------------------------------------------------------
murphyz's Profile: http://www.excelforum.com/member.php...o&userid=20624
View this thread: http://www.excelforum.com/showthread...hreadid=484219

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy sheet and prompt for sheet name

Oh sorry, I meant "" by empty string, not FALSE.

So try to replace:

If mystring = False Then
by
If mystring = "" Then

Beware I did not test what I am saying, but am believing it works.

Stefano

--
Stefano Gatto


"murphyz" wrote:


Thank you, I'm getting there slowly.

I now have it almost working perfectly, although when pressing cancel
it ignores my 'you clicked cancel' text and prints out the 'you didn't
enter anything' text - am I missing something silly?

mystring = InputBox("Please enter sheet name here")
If mystring = False Then
MsgBox "You clicked cancel"
ElseIf mystring = "" Then
MsgBox "You didn't enter anything"
Else
Sheets("Template.com").Visible = True
Sheets("Template.com").Select
Sheets("Template.com").Copy After:=Sheets(2)
Sheets("Template.com (2)").Select
Sheets("Template.com (2)").Name = mystring
Sheets("Template.com").Select
ActiveWindow.SelectedSheets.Visible = False
End If

Finally, is there a way to copy the sheet to the very end of the tabs -
Copy After:=Sheets(2) - regardless of how many worksheets there are?

Many thanks

Mxx


--
murphyz
------------------------------------------------------------------------
murphyz's Profile: http://www.excelforum.com/member.php...o&userid=20624
View this thread: http://www.excelforum.com/showthread...hreadid=484219


Reply
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
copy rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
Auto Copy/autofill Text from sheet to sheet if meets criteria Joyce Excel Discussion (Misc queries) 0 November 20th 08 11:05 PM
'Copy to' Advance Filter depend only on sheet ID not start sheet Sandy Yates Excel Worksheet Functions 0 April 4th 06 03:48 AM
how to find and copy values on sheet 2, based on a list on sheet 1 evanmacnz Excel Programming 4 February 7th 05 08:33 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. RonMc5 Excel Discussion (Misc queries) 9 February 3rd 05 12:51 AM


All times are GMT +1. The time now is 09:28 AM.

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

About Us

"It's about Microsoft Excel"