I have created a UserForm that adds TextBoxes and CommandButtons dynamically based on the data in my spreadsheet.
I have successfully been able to fill in the TextBoxes with the correct information.
I cannot figure how to dynamically add a "CommandButton_Click" sub to my command buttons.
Here is my code so far for my UserFrom:
Thanks for any help.
I have successfully been able to fill in the TextBoxes with the correct information.
I cannot figure how to dynamically add a "CommandButton_Click" sub to my command buttons.
Here is my code so far for my UserFrom:
Code:
Private Sub UserForm_Activate()
On Error Resume Next
Sheets("Data").Select
LotInputs.TextBoxLotCode = Range("ZE2")
LotInputs.TextBoxLotDate = Range("ZC2")
For xRow = 2 To Range("ZK2")
Set ctl = Me.Controls.Add("Forms.Textbox.1") 'add text box
With ctl
.Visible = True
.Width = 150
.Height = 15.75
.Left = 6
.Top = 102 + (xRow - 1) * 18
.Name = "TextBoxInputLot" & xRow
.Value = Range("ZP" & xRow)
End With
Set ctl = Me.Controls.Add("Forms.CommandButton.1") 'add command button
With ctl
.Visible = True
.Width = 15.75
.Height = 15.75
.Left = 156
.Top = 102 + (xRow - 1) * 18
.Name = "CommandButtonInput" & xRow
.Caption = "^"
End With
Me.Height = Me.Height + 18
Next xRow
End Sub
Thanks for any help.