My makro adds a worksheet but I want it to include some preset data

Griffin29

New Member
Joined
Oct 18, 2013
Messages
16
Hi Folks,

with some help from here (thank you again) I have been using a macro that makes a new sheet which is named the same as the highlighted cell. Works brilliantly but I now need it to add more information (it currently pastes the sheet name only).

Ideally I have another sheet set up called 'Template' and I would like to insert all the data (it is only text) into the newly created sheet. If I select the Template sheet (or a range called template ), I cant seem to get back to the newly created sheet to do the paste.

Help :-)

Here is the code I am currently using

Public Sub Insertsheet()


With ActiveCell
If .Value <> Empty Then
If Not Evaluate("ISREF('" & .Value & "'!A1)") Then 'Test if worksheet name exists
Worksheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = .Value
Range("A1").Value = .Value
.Parent.Hyperlinks.Add Anchor:=.Cells(1), Address:="", SubAddress:="'" & .Value & "'!A1", TextToDisplay:=.Value
'.Parent.Select
Else
MsgBox "A sheet named '" & .Value & "' already exists. ", vbExclamation, "Invalid Sheet Name"
End If
End If
End With

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Why not just copy the template sheet.
Code:
Public Sub Insertsheet()
With ActiveCell
   If .Value <> Empty Then
      If Not Evaluate("ISREF('" & .Value & "'!A1)") Then 'Test if worksheet name exists
         Sheets("Template").Copy After:=Sheets(Sheets.Count)
         ActiveSheet.Name = .Value
         Range("A1").Value = .Value
         .Parent.Hyperlinks.Add Anchor:=.Cells(1), Address:="", SubAddress:="'" & .Value & "'!A1", TextToDisplay:=.Value
         '.Parent.Select
      Else
         MsgBox "A sheet named '" & .Value & "' already exists. ", vbExclamation, "Invalid Sheet Name"
      End If
   End If
End With
End Sub
 
Upvote 0
That is brilliant - thank you I couldn't for the life of me work it out and it's so much more elegant than what I was trying
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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