PC Review


Reply
Thread Tools Rate Thread

Copying a formatted "template" sheet and naming new sheet via user form

 
 
Neale
Guest
Posts: n/a
 
      31st May 2007
Hi. I've done some hunting around and reading and came up with the
following code that creates a new blank sheet and names it via a user
form, but I can't work out how to do the same thing if I want to use a
formatted template worksheet. Please help!

Sample code I've come up with so far:

'Create a new blank worksheet
'Name the worksheet by entering the employee name and number
'in the appropriate boxes
'Clicking OK will transfer the name to the worksheet tab
Private Sub cbNewEmpSheetNameFormOK_Click()
Dim NewSheet As Worksheet
On Error Resume Next
Set NewSheet = Worksheets(tbxNewEmpSheetNameFormName.Text & "-" _
& tbxNewEmpSheetNameFormNo.Text)
If Err > 0 Or NewSheet Is Nothing Then
Worksheets.Add before:=Worksheets(Worksheets.Count)
ActiveSheet.Name = tbxNewEmpSheetNameFormName.Text & "-" _
& tbxNewEmpSheetNameFormNo.Text
Worksheets(2).Select
'The sheet is checked to ensure that it's not a duplicate of an
already existing sheet
Else
Beep
MsgBox "Sheet already exists!"
End If
Unload Me
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RlN0MQ==?=
Guest
Posts: n/a
 
      31st May 2007
hi,
understand. VB is not psychic. you have to tell it everything.
in the code you posted, VB is getting the naming criterial from 2 text boxes
on the form. the information got into the text box somehow....how?.....??
so if you are not using a form, you can put the information in cells. say A1
and A2'
replace
ActiveSheet.Name = tbxNewEmpSheetNameFormName.Text & "-" _
& tbxNewEmpSheetNameFormNo.Text
with
Dim one As Range
Dim two As Range
Set one = Sheet1.Range("A1")
Set two = Sheet1.Range("A2")
Sheets.Add
ActiveSheet.Name = one.Value & "-" & two.Value

worked in xl3k
regards
FSt1

"Neale" wrote:

> Hi. I've done some hunting around and reading and came up with the
> following code that creates a new blank sheet and names it via a user
> form, but I can't work out how to do the same thing if I want to use a
> formatted template worksheet. Please help!
>
> Sample code I've come up with so far:
>
> 'Create a new blank worksheet
> 'Name the worksheet by entering the employee name and number
> 'in the appropriate boxes
> 'Clicking OK will transfer the name to the worksheet tab
> Private Sub cbNewEmpSheetNameFormOK_Click()
> Dim NewSheet As Worksheet
> On Error Resume Next
> Set NewSheet = Worksheets(tbxNewEmpSheetNameFormName.Text & "-" _
> & tbxNewEmpSheetNameFormNo.Text)
> If Err > 0 Or NewSheet Is Nothing Then
> Worksheets.Add before:=Worksheets(Worksheets.Count)
> ActiveSheet.Name = tbxNewEmpSheetNameFormName.Text & "-" _
> & tbxNewEmpSheetNameFormNo.Text
> Worksheets(2).Select
> 'The sheet is checked to ensure that it's not a duplicate of an
> already existing sheet
> Else
> Beep
> MsgBox "Sheet already exists!"
> End If
> Unload Me
> End Sub
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying a template sheet and inputting a formula into another sheetthat references the new sheet A & S Microsoft Excel Programming 1 29th Jul 2009 08:59 PM
Workbook "Sheet" Naming comotoman Microsoft Excel Misc 4 30th Sep 2005 09:49 PM
Copying Items from Worksheets to a "Sumation Sheet"? turner2000 Microsoft Excel Worksheet Functions 1 27th Sep 2004 11:16 PM
VBA for bringing up "User Template in File System" from "Choose Form"?? StargateFan Microsoft Outlook VBA Programming 1 30th Aug 2004 02:50 PM
VBA for bringing up "User Template in File System" from "Choose Form"?? StargateFan Microsoft Outlook VBA Programming 2 27th Aug 2004 06:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:27 AM.