djburnheim
Technical User
Hi,
I'm trying to automatically create a number of checkboxex on a form when it initialises based on data in sheet. The number of checkboxex will vary depending on how many cells in the sheet have values in them.
The only way I can think to do it is to create a whole heap of genric checkboxex and then loop through them changing the caption to match the cell value and then hide/delete ones that aren't changed but I'd really like to do it dynamically. I've got the code below which will automatically create a single control but if I need to create 10 or 20 different checkboxes how can I get them neatly organised on a form?
Public Sub CreateTextBoxes()
Dim Test As String
Dim myText As TextBox
Dim NewTextBox As MSForms.TextBox
Dim T As String
T = "ABC"
Test = PropertyList(1)
'MsgBox test
Set NewTextBox = Me.Controls.Add("Forms.textbox.1", T)
With NewTextBox
.name = T
.Top = 20
.Left = 150
.Width = 150
.height = 12
.Font.Size = 7
.Font.name = "Tahoma"
.BorderStyle = fmBorderStyleSingle
.SpecialEffect = fmSpecialEffectFlat
End With
NewTextBox.Value = "123"
End Sub
Any suggestions or just go with ?
I'm trying to automatically create a number of checkboxex on a form when it initialises based on data in sheet. The number of checkboxex will vary depending on how many cells in the sheet have values in them.
The only way I can think to do it is to create a whole heap of genric checkboxex and then loop through them changing the caption to match the cell value and then hide/delete ones that aren't changed but I'd really like to do it dynamically. I've got the code below which will automatically create a single control but if I need to create 10 or 20 different checkboxes how can I get them neatly organised on a form?
Public Sub CreateTextBoxes()
Dim Test As String
Dim myText As TextBox
Dim NewTextBox As MSForms.TextBox
Dim T As String
T = "ABC"
Test = PropertyList(1)
'MsgBox test
Set NewTextBox = Me.Controls.Add("Forms.textbox.1", T)
With NewTextBox
.name = T
.Top = 20
.Left = 150
.Width = 150
.height = 12
.Font.Size = 7
.Font.name = "Tahoma"
.BorderStyle = fmBorderStyleSingle
.SpecialEffect = fmSpecialEffectFlat
End With
NewTextBox.Value = "123"
End Sub
Any suggestions or just go with ?