PDA

View Full Version : Solved: Userform to start with another worksheet



RonNCmale
11-10-2012, 05:23 PM
I found the following code to populate a userform with my worksheets, I'm looking to add to this code to start with worksheet 4 instead of worksheet 1 in populating the userform.



Private Sub CheckBox1_Click()
Dim iloop As Integer
For iloop = 1 To ListBox1.ListCount
ListBox1.Selected(iloop - 1) = CheckBox1.Value
Next
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim iloop As Integer
For iloop = 1 To ListBox1.ListCount
If ListBox1.Selected(iloop - 1) = True Then
Sheets(ListBox1.List(iloop - 1, 0)).PrintOut
ListBox1.Selected(iloop - 1) = False
End If
Next
End Sub
Private Sub UserForm_Initialize()
Dim sSheet
For Each sSheet In Sheets
If sSheet.Type = 3 Then 'Chart sheet
ListBox1.AddItem sSheet.Name
ElseIf WorksheetFunction.CountA(sSheet.Cells) > 0 Then
ListBox1.AddItem sSheet.Name
End If
Next sSheet
End Sub

mikerickson
11-10-2012, 05:58 PM
Try this
Dim i As Long, sSheet As Worksheet

For i = 4 to Sheets.Count
Set sSheet = Sheets(i)
If sSheet.Type = 3 Then 'Chart sheet
ListBox1.AddItem sSheet.Name
ElseIf WorksheetFunction.CountA(sSheet.Cells) > 0 Then
ListBox1.AddItem sSheet.Name
End If
Next i

RonNCmale
11-10-2012, 06:09 PM
Works Great thanks