Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a new worksheet using an userform

Status
Not open for further replies.

vitheshan

Technical User
Jul 15, 2015
3
US
Hi,

I currently have a userform with 2 textboxes and a combobox
I'd like to use the value in there boxes to create a new worksheet with the name of the worksheet being the values in the boxes on the userform

Regards,

Paul
 
[tt]Worksheets.Add[/tt] adds worksheet to a specific location (set in argument) and returns reference to this worksheet. Change its name to any text that follows naming rules. Start with workbook reference for specific workbook. If you don't need a reference to the worksheet:
[tt]Worksheets.Add.Name = "New worksheet"[/tt]


combo
 
I need to refer to a value in a userform, is there a way of doing this?

I have a user form with a textbox where you type in the new project's name and then click on a button to create a new worksheet with the name of the project
 
You can use Text of the textbox as a variable for the name of newly created worksheet.

combo
 
I have CommandButton1 and Text1 on the UserForm:

Code:
Option Explicit

Private Sub CommandButton1_Click()
[green]
'Add new sheet as the last sheet in the workbook[/green]
Worksheets.Add after:=Worksheets(Worksheets.Count)[green]
'Name it from text box[/green]
Sheets(Sheets.Count).Name = TextBox1.Text

End Sub

You still have to ensure the names for sheets are unique, not too long, etc.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Shorter version of the same:

Code:
With Sheets
    .Add after:=Sheets(.Count)
    Sheets(.Count).Name = TextBox1.Text
End With

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Andy said:
Shorter version of the same:
And the shorter version:
[tt]Sheets.Add(after:=Sheets(Sheets.Count)).Name = TextBox1.Text[/tt]

combo
 
Thank you very much
That worked perfectly

Much appreciated
 
It is customary on TT to mark the helpful post(s) with the Star.
Just click on Great post? Star it link.
This way others may easily see which post was helpful.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top