Add new worksheet with formatted layout

fivegallon

Board Regular
Joined
Jun 26, 2005
Messages
50
Hi, i'm wanting to add a new worksheet when i add an entry to an index page with the same name as the new entry.
I have the code for this bit already.
What i would like it to do is to copy an existing sheet that already has the layout i require rather than just a new blank sheet

My workbook is multiple worksheets on motor testing data.
The first page is "Index".
Each entry is hyperlinked to subsequent worksheets of motor test data.

The second page is "Motor Info Sheet Blank".
This is the page i would like to copy

I would prefer if i can insert the new page immediately into the "third" position each time rather than at the "end".
This will keep the most recent data within initial view. If this part can't be done and it needs to go to the "end", then no big deal

Here is my current code:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br><SPAN style="color:#00007F">Dim</SPAN> wsNew <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">If</SPAN> Target.Cells.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br>****<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>****<SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(Target, Range("A1:A50")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>****<SPAN style="color:#00007F">Set</SPAN> wsNew = Sheets(Target.Text)<br>****<SPAN style="color:#00007F">If</SPAN> wsNew <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> Sheets.Add().Name = Target.Text<br>****<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Edit: i'm using Excel 2007
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi, i'm wanting to add a new worksheet when i add an entry to an index page with the same name as the new entry.
I have the code for this bit already.
What i would like it to do is to copy an existing sheet that already has the layout i require rather than just a new blank sheet

My workbook is multiple worksheets on motor testing data.
The first page is "Index".
Each entry is hyperlinked to subsequent worksheets of motor test data.

The second page is "Motor Info Sheet Blank".
This is the page i would like to copy

I would prefer if i can insert the new page immediately into the "third" position each time rather than at the "end".
This will keep the most recent data within initial view. If this part can't be done and it needs to go to the "end", then no big deal

Here is my current code:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br><SPAN style="color:#00007F">Dim</SPAN> wsNew <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">If</SPAN> Target.Cells.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br>****<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>****<SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(Target, Range("A1:A50")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>****<SPAN style="color:#00007F">Set</SPAN> wsNew = Sheets(Target.Text)<br>****<SPAN style="color:#00007F">If</SPAN> wsNew <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> Sheets.Add().Name = Target.Text<br>****<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Edit: i'm using Excel 2007

Maybe?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next
If Not Intersect(Target, Range("A1:A50")) Is Nothing Then
    With Sheets("Motor Info Sheet Blank")
        .Copy Before:=Sheets(3) 'the name of the sheet in the third position
        .Name = Target.Text
    End With
    With Sheets("Motor Info Sheet Blank (2)")
        .Name = "Motor Info Sheet Blank"
    End With
End If
End Sub
 
Upvote 0
John, that works a treat. Very much appreciated.

Maybe?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next
If Not Intersect(Target, Range("A1:A50")) Is Nothing Then
    With Sheets("Motor Info Sheet Blank")
        .Copy Before:=Sheets(3) 'the name of the sheet in the third position
        .Name = Target.Text
    End With
    With Sheets("Motor Info Sheet Blank (2)")
        .Name = "Motor Info Sheet Blank"
    End With
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top