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
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,731
Messages
5,513,068
Members
408,935
Latest member
Jmtramos

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top