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?
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