Trying to name a newly created worksheet with vba

knacksc2

Board Regular
Joined
Jan 23, 2014
Messages
63
so i have a macro that creates a new worksheet by copying a template and moving it to the end. I have tried lots of different things and cannot figure out why none work. its like the only thing the .name = will do is accept something in quotes. please tell me this isnt so. below is my massacred macro:

Code:
'Dim MySheetName As String'MySheetName = UserForm1.TextBox1.Value & " " & Range("Dated").String
    Sheets("Template").Select
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    Sheets("Template (2)").Select
'    Sheets("Template (2)").Name = MySheetName
Cells(3, 2).Value = UserForm1.TextBox1.Value
Cells(3, 3).Value = Range("Dated").Value


Cells(5, 4).Value = UserForm1.TextBox1.Value
Cells(6, 4).Value = UserForm1.TextBox2.Value
Cells(7, 4).Value = UserForm1.TextBox3.Value
Cells(8, 4).Value = UserForm1.TextBox4.Value


Cells(3, 2).Value = Cells(3, 2).Value & " " & Cells(3, 3).Value
Cells(3, 3).ClearContents
Range("Catch1").Value = Cells(3, 2).Value
UserForm1.Hide
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about something like this:

<font face=Calibri>    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br>        <br>        Sheets("Template").Copy After:=Sheets(Sheets.Count)<br>        <SPAN style="color:#00007F">Set</SPAN> ws = ActiveSheet<br>        ws.Name = MySheetName<br>        </FONT>

HTH,
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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