Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba-excel-training - creating new sheets

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » vba-excel-training - Creating new sheets

vba-excel-training - Creating new sheets

ResolvedVersion Standard

Tom has attended:
Excel VBA Intro Intermediate course

Creating new sheets

Is it possible to have a userform from which more than one value can be picked, and then to create one sheet for every value?

Edited on Mon 10 Dec 2007, 11:46

RE: creating new sheets

Hi Tom

The short answer to this is Yes.

The instructions below use object names I thought up as examples. You can change these names to suit your needs

You need to create a Form "frmNewSheets", with a List Box 'lstSheetNames" and a Button "cmdOK"

In the ListBox properties make sure MultiSelect is on 2 whiuch needs the Shift and Control buttons for multi selection

The in the code area for the m add the following code:

Private Sub cmdOK_Click() 'Takes the names from the list box an creates sheets with the names

Dim i As Integer 'Counts the number of items in the list

For i = 0 To lstSheetNames.ListCount - 1 'The -1 is needed as lists start at 0

If lstSheetNames.Selected(i) = True Then

Sheets.Add After:=Sheets(Sheets.Count) 'Add sheet at end
ActiveSheet.Name = lstSheetNames.List(i) 'Renames the sheet to the selected value

End If

Next i

End Sub
'==========================================
Private Sub UserForm_Initialize() 'Adds the names to the List Box

With Me.lstSheetNames

.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"

End With

End Sub


Hope this helps

Carlos

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Hide separate columns in Excel 2010

If you want to hide columns not adjacent to each other for example, Columns A, C and E then:-

1) Click on the fist column to be hidden i.e. A

2) Press and hold down the CTRL key

3) While holding the CTRL key, left click on the rest of the columns you want to hide i.e. C and E

4) Right click and choose Hide

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.