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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
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
 

fivegallon

Board Regular
Joined
Jun 26, 2005
Messages
50
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,398
Messages
5,831,407
Members
430,065
Latest member
ctornabe

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
Top