VBA Code to make and name a new worksheet?

akaj321akaj

New Member
Joined
May 23, 2011
Messages
11
Hello,
im trying to make a vba code that will read what you have in a textbox named "categories" and when you click the "insert category" button Ive made,
It will automatically create a new worksheet with the name you entered in the textbox.
if this is possible please tell me, thank you very much in advance!
 

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.
I have a code that works

Dim WS As Worksheet
Set WS = Sheets.Add

but im trying to make it get the text that i type in my textbox "txtcat" to come up with the name for the new worksheet
 
Upvote 0
Code:
Sub InsertSheet()
    
    Dim sh As Worksheet
    
    Set sh = Sheets.Add
    sh.Name = txtcat.Text
    
End Sub

Or this way:
Code:
Sub InsertSheet()
    Sheets.Add.Name = txtcat.Text
End Sub
 
Upvote 0
You can create copy of your template sheet like this:
Code:
Sub SheetFromTemplate()
    Worksheets("Template").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = txtcat.Text
End Sub
 
Upvote 0
Thanks for the reply sektor! sorry that i haven't posted in a while but what your saying
is exactly what i want but i cant find out how to incorporate that into a commandbutton:(
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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