I was able to write a macro that will build a Userform from scratch and add labels and combo boxes if there are values in certain cells, using the following:
Cells A1 through F1 have strings in them, thus 6 labels and comboboxes are added.
What I would like to do is add a MultiPage, and split these labels and comboboxes into 3 different pages.
I was able to figure out how to create a MultiPage with 3 pages onto a UserForm through a macro with this.
What I can't figure out is how to combine these 2 Macros into 1.
I want it to make the UserForm, then add in a MultiPage and then in the Multipage add Labels and Comboboxes.
Any help would be much appreciated.
Code:
Sub Testing()
Dim TrackForm As VBComponent
Dim tCB As MSForms.ComboBox
Dim tLB As MSForms.Label
Dim Numb As Worksheet
Set Numb = Worksheets("Numbers")
Dim Track As String
Dim oRow As Integer
Dim oCol As Integer
Dim Tval As Integer
oRow = 1
oCol = 15
Tval = 10
' Making Form
Set TrackForm = ActiveWorkbook.VBProject _
.VBComponents.Add(vbext_ct_MSForm)
With TrackForm
.Properties("Height") = 400
.Properties("Width") = 350
On Error Resume Next
.Properties("Caption") = "Please select Track Codes"
End With
For oCol = 15 To 69
Track = Numb.Cells(oRow, oCol).Value
If Track <> "" Then
Set tLB = TrackForm.Designer.Controls.Add("Forms.Label.1")
With tLB
.Name = "tName"
.Caption = Track
.Left = 25
.Top = Tval
.Height = 12
.Width = 150
.Font.Size = 10
End With
Set tCB = TrackForm.Designer.Controls.Add("Forms.ComboBox.1")
With tCB
.Name = "tCode"
.Left = 170
.Top = Tval
.Height = 16
.Width = 150
End With
Tval = Tval + 16
End If
Next oCol
ShowTForm
End Sub
Cells A1 through F1 have strings in them, thus 6 labels and comboboxes are added.
What I would like to do is add a MultiPage, and split these labels and comboboxes into 3 different pages.
I was able to figure out how to create a MultiPage with 3 pages onto a UserForm through a macro with this.
Code:
Sub Testing()
Dim TrackForm As VBComponent
Dim tMP As MSForms.MultiPage
' Making Form
Set TrackForm = ActiveWorkbook.VBProject _
.VBComponents.Add(vbext_ct_MSForm)
With TrackForm
.Properties("Height") = 400
.Properties("Width") = 350
On Error Resume Next
.Properties("Caption") = "Please select Track Codes"
End With
Set tMP = TrackForm.Designer.Controls.Add("Forms.MultiPage.1")
With tMP
.Name = "HostMP"
.Width = 325
.Height = 200
.Left = 10
.Top = 70
.Pages(0).Name = "Socal"
.Pages(0).Caption = "Socal Host"
.Pages(1).Name = "Losal"
.Pages(1).Caption = "Los Alamitos Host"
.Pages.Add.Name = "CalX"
.Pages(2).Caption = "Cal Expo Host"
End With
ShowTForm
End Sub
What I can't figure out is how to combine these 2 Macros into 1.
I want it to make the UserForm, then add in a MultiPage and then in the Multipage add Labels and Comboboxes.
Any help would be much appreciated.