Try something like this - it relies on having a commandbutton already on the userform (but it moves it to the right place...)
Option Explicit
Private Sub CreateControls()
Dim ws As Worksheet
Dim i As Integer
Dim cBox As MSForms.CheckBox
Dim iPos As Integer
iPos = 5
For i = 1 To Worksheets.Count
Set ws = Worksheets(i)
If Not ws.Name = "Main" Then
Set cBox = Me.Controls.Add("Forms.Checkbox.1", "Checkbox" & i, True)
With cBox
.Top = iPos
.Left = 5
.Width = 80
.Caption = Worksheets(i).Name
End With
iPos = iPos + 15
End If
Next i
With Me.CommandButton1
.Top = iPos + 5
.Left = 5
.Width = 80
.Caption = "Button Caption"
End With
Me.Height = iPos + 60
Me.Width = 30
End Sub
Private Sub CommandButton1_Click()
Dim cb As Control
Dim s As String
For Each cb In Me.Controls
If TypeName(cb) = "CheckBox" Then
s = s & cb.Caption & vbTab & cb.Value & vbCr
End If
Next cb
MsgBox s
End Sub
Private Sub UserForm_Initialize()
Call CreateControls
End Sub
Bookmarks