98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » vba-excel-training - Creating new sheets
vba-excel-training - Creating new sheets
Resolved · Low Priority · Version 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?
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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Screen Splitters in ExcelScreen splitter icons can be set from the ribbon bar, or dragged from the scroll bars. The icon just above the up arrow on the right scroll bar controls the horizontal splitter; the icon to the right of the right arrow on the bottom scroll bar controls the vertical splitter. |