CABBA
12-12-2017, 12:55 AM
I am creating a userform where by which several text boxes (up to 60) are created in runtime based on the number of periods that the user enters.
i used this code to create the text boxes:
Set txtCntrl = .Add("Forms.TextBox.1", "txtDemand" & txtT, True) 'in this case txtT is incrementing up to the number of periods
and so in this case i end up with several textboxes (txtDemand1, txtDemand2, .....)
when the user clicks OK i want to take all the values from the form and put them into a sheet.
i have found that the following line works fine (in this example taking the value in txtDemand1 and putting it into cell "A46"):
Range("A46") = frmAggPlan!txtdemand1.Value
The problem is that i want to automate this some how using a variable and concatenating it. but i dont it seems that the i can not do this in the same way that i created the boxes. For example i would like to set up a looop on user press ok like this.
Dim i As Integer
For i = 1 to txtT
Range ("A46").offset(i-1) = frmAggPlan!txtDemand & i 'i'm not able to concatenate like this here, so looking for a way to have all the runtime created text boxes to output to my sheet
Next i
Any help would be welcome.
i used this code to create the text boxes:
Set txtCntrl = .Add("Forms.TextBox.1", "txtDemand" & txtT, True) 'in this case txtT is incrementing up to the number of periods
and so in this case i end up with several textboxes (txtDemand1, txtDemand2, .....)
when the user clicks OK i want to take all the values from the form and put them into a sheet.
i have found that the following line works fine (in this example taking the value in txtDemand1 and putting it into cell "A46"):
Range("A46") = frmAggPlan!txtdemand1.Value
The problem is that i want to automate this some how using a variable and concatenating it. but i dont it seems that the i can not do this in the same way that i created the boxes. For example i would like to set up a looop on user press ok like this.
Dim i As Integer
For i = 1 to txtT
Range ("A46").offset(i-1) = frmAggPlan!txtDemand & i 'i'm not able to concatenate like this here, so looking for a way to have all the runtime created text boxes to output to my sheet
Next i
Any help would be welcome.